annotate website/src/fschmidt/stopwatch.html @ 1292:a6892dcf5659

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Jan 2019 15:01:36 -0700
parents fb802d8aba0b
children 007ceb8dcf89
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 button:focus {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 outline: inherit;
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 </style>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <script>
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 function now() {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 return Math.floor(Date.now()/1000);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
25 function show() {
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 var start = localStorage.start;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 var time;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 if( !start ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 time = 0;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 } else {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 var stop = localStorage.stop || now();
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 time = stop - start;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 var seconds = time % 60;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 time = Math.floor(time/60);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 var minutes = time % 60;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 time = Math.floor(time/60);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 var hours = time;
1287
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
39 seconds = ('0'+seconds).slice(-2);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
40 minutes = ('0'+minutes).slice(-2);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
41 time = hours + ':' + minutes + ':' + seconds;
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 document.querySelector('[time]').innerHTML = time;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
44 // fix buttons
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 var isRunning = localStorage.start && !localStorage.stop;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 if( isRunning ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 document.querySelector('[start]').style.display = 'none';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 document.querySelector('[stop]').style.display = 'inline-block';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 document.querySelector('[reset]').style.display = 'none';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 } else {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 document.querySelector('[start]').style.display = 'inline-block';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 document.querySelector('[stop]').style.display = 'none';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 if( localStorage.start ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 document.querySelector('[reset]').style.display = 'inline-block';
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 } else {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 document.querySelector('[reset]').style.display = 'none';
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 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 function start() {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 var stop = localStorage.stop;
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 if( !stop ) {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 localStorage.start = now();
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 } else {
1287
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
66 localStorage.removeItem('stop');
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 localStorage.start = now() - (stop - localStorage.start);
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 }
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
69 show();
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 function stop() {
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 localStorage.stop = now();
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
74 show();
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 function reset() {
1287
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
78 localStorage.removeItem('start');
Franklin Schmidt <fschmidt@gmail.com>
parents: 1285
diff changeset
79 localStorage.removeItem('stop');
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
80 show();
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 function loaded() {
1292
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
84 show();
Franklin Schmidt <fschmidt@gmail.com>
parents: 1290
diff changeset
85 setInterval(show,1000);
1285
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 }
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 </script>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 </head>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 <body onload="loaded()">
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 <h1 time></h1>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 <button start onclick="start()">start</button>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 <button stop onclick="stop()">stop</button>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 <button reset onclick="reset()">reset</button>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 </body>
fad40fe3282d add personal web tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 </html>