annotate website/src/fschmidt/stopwatch.html @ 1293:007ceb8dcf89

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 06 Jan 2019 14:09:24 -0700
parents a6892dcf5659
children 2555154ad19f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 <!doctype html>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 <html>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 <head>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 <meta name="viewport" content="width=device-width, initial-scale=1">
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 <style>
1290
Franklin Schmidt <fschmidt@gmail.com>
parents: 1287
diff changeset
6 body {
Franklin Schmidt <fschmidt@gmail.com>
parents: 1287
diff changeset
7 text-align: center;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1287
diff changeset
8 }
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 button {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 cursor: pointer;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 font-size: 1em;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 border-radius: 6px;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 display: none;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 </style>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 <script>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 function now() {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 return Math.floor(Date.now()/1000);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
22 function show() {
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 var start = localStorage.start;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 var time;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 if( !start ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 time = 0;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 } else {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 var stop = localStorage.stop || now();
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 time = stop - start;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 var seconds = time % 60;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 time = Math.floor(time/60);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 var minutes = time % 60;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 time = Math.floor(time/60);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 var hours = time;
1287
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
36 seconds = ('0'+seconds).slice(-2);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
37 minutes = ('0'+minutes).slice(-2);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
38 time = hours + ':' + minutes + ':' + seconds;
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 document.querySelector('[time]').innerHTML = time;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
41 // fix buttons
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 var isRunning = localStorage.start && !localStorage.stop;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 if( isRunning ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 document.querySelector('[start]').style.display = 'none';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 document.querySelector('[stop]').style.display = 'inline-block';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 document.querySelector('[reset]').style.display = 'none';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 } else {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 document.querySelector('[start]').style.display = 'inline-block';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 document.querySelector('[stop]').style.display = 'none';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 if( localStorage.start ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 document.querySelector('[reset]').style.display = 'inline-block';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 } else {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 document.querySelector('[reset]').style.display = 'none';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 function start() {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 var stop = localStorage.stop;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 if( !stop ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 localStorage.start = now();
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 } else {
1287
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
63 localStorage.removeItem('stop');
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 localStorage.start = now() - (stop - localStorage.start);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 }
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
66 show();
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 function stop() {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 localStorage.stop = now();
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
71 show();
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 function reset() {
1287
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
75 localStorage.removeItem('start');
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
76 localStorage.removeItem('stop');
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
77 show();
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 function loaded() {
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
81 show();
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
82 setInterval(show,1000);
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 </script>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 </head>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 <body onload="loaded()">
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 <h1 time></h1>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 <button start onclick="start()">start</button>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 <button stop onclick="stop()">stop</button>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 <button reset onclick="reset()">reset</button>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 </body>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 </html>