Really implement a chronometer master
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Sat, 8 Jun 2013 19:10:57 +0000 (16:10 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Sat, 8 Jun 2013 19:10:57 +0000 (16:10 -0300)
index.html
pomo.appcache
pomo.js [new file with mode: 0644]

index dba067d..1e027e5 100644 (file)
@@ -1,10 +1,14 @@
 <html>
 <head>
 <title>Pomo</title>
 <html>
 <head>
 <title>Pomo</title>
-<script src="/install.js"></script>
 </head>
 <body>
 </head>
 <body>
+<div id="pomo">
+</div>
 <div id="status">
 </div>
 <div id="status">
 </div>
+<audio src="/media/alarm.ogg" id="alarm"></audio>
+<script src="/install.js"></script>
+<script src="/pomo.js"></script>
 </body>
 </html>
 </body>
 </html>
index 4112eae..1e9cdac 100644 (file)
@@ -1,5 +1,6 @@
 CACHE MANIFEST
 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/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 (file)
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();