From 7e874b3d502201f8e2382958e0f6f37c507579e9 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sat, 8 Jun 2013 16:10:57 -0300 Subject: [PATCH] Really implement a chronometer --- index.html | 6 +++++- pomo.appcache | 3 ++- pomo.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 pomo.js diff --git a/index.html b/index.html index dba067d..1e027e5 100644 --- a/index.html +++ b/index.html @@ -1,10 +1,14 @@ Pomo - +
+
+ + + diff --git a/pomo.appcache b/pomo.appcache index 4112eae..1e9cdac 100644 --- a/pomo.appcache +++ b/pomo.appcache @@ -1,5 +1,6 @@ CACHE MANIFEST -# v1 +# v2 http://pomo.cascardo.info/index.html http://pomo.cascardo.info/install.js http://pomo.cascardo.info/images/*.png +http://pomo.cascardo.info/media/* diff --git a/pomo.js b/pomo.js new file mode 100644 index 0000000..88646f7 --- /dev/null +++ b/pomo.js @@ -0,0 +1,46 @@ +MILS_PER_SECOND = 1000; +MILS_PER_MINUTE = 60 * MILS_PER_SECOND; +MILS_PER_HOUR = 60 * MILS_PER_MINUTE; + +function Pomo() { + var p = this; + this.pomo = document.getElementById("pomo"); + this.start = function() { + this.date = new Date(); + setTimeout(function() { + p.update(); + }, 500); + }; + this.prefix = function(i) { + if (i < 10) { + i = "0" + i; + } + return i; + } + this.update = function() { + var now = new Date(); + var mils = this.date.getTime() + 25 * MILS_PER_MINUTE - now.getTime(); + if (mils < 0) { + this.alarm(); + mils = 0; + } else { + setTimeout(function() { + p.update(); + }, 500); + } + var hours = Math.floor(mils / MILS_PER_HOUR); + mils -= hours * MILS_PER_HOUR; + var minutes = Math.floor(mils / MILS_PER_MINUTE); + mils -= minutes * MILS_PER_MINUTE; + var seconds = Math.floor(mils / MILS_PER_SECOND); + var s_date = this.prefix(hours) + ":" + this.prefix(minutes) + ":" + this.prefix(seconds); + this.pomo.innerHTML = s_date; + }; + this.alarm = function() { + var audio = document.getElementById("alarm"); + audio.play(); + } +} + +var pomo = new Pomo(); +pomo.start(); -- 2.20.1