Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1291:2bbc6f132d61 | 1292:a6892dcf5659 |
---|---|
20 | 20 |
21 function now() { | 21 function now() { |
22 return Math.floor(Date.now()/1000); | 22 return Math.floor(Date.now()/1000); |
23 } | 23 } |
24 | 24 |
25 function showTime() { | 25 function show() { |
26 var start = localStorage.start; | 26 var start = localStorage.start; |
27 var time; | 27 var time; |
28 if( !start ) { | 28 if( !start ) { |
29 time = 0; | 29 time = 0; |
30 } else { | 30 } else { |
38 var hours = time; | 38 var hours = time; |
39 seconds = ('0'+seconds).slice(-2); | 39 seconds = ('0'+seconds).slice(-2); |
40 minutes = ('0'+minutes).slice(-2); | 40 minutes = ('0'+minutes).slice(-2); |
41 time = hours + ':' + minutes + ':' + seconds; | 41 time = hours + ':' + minutes + ':' + seconds; |
42 document.querySelector('[time]').innerHTML = time; | 42 document.querySelector('[time]').innerHTML = time; |
43 } | |
44 | 43 |
45 function fixButtons() { | 44 // fix buttons |
46 var isRunning = localStorage.start && !localStorage.stop; | 45 var isRunning = localStorage.start && !localStorage.stop; |
47 if( isRunning ) { | 46 if( isRunning ) { |
48 document.querySelector('[start]').style.display = 'none'; | 47 document.querySelector('[start]').style.display = 'none'; |
49 document.querySelector('[stop]').style.display = 'inline-block'; | 48 document.querySelector('[stop]').style.display = 'inline-block'; |
50 document.querySelector('[reset]').style.display = 'none'; | 49 document.querySelector('[reset]').style.display = 'none'; |
65 localStorage.start = now(); | 64 localStorage.start = now(); |
66 } else { | 65 } else { |
67 localStorage.removeItem('stop'); | 66 localStorage.removeItem('stop'); |
68 localStorage.start = now() - (stop - localStorage.start); | 67 localStorage.start = now() - (stop - localStorage.start); |
69 } | 68 } |
70 fixButtons(); | 69 show(); |
71 } | 70 } |
72 | 71 |
73 function stop() { | 72 function stop() { |
74 localStorage.stop = now(); | 73 localStorage.stop = now(); |
75 fixButtons(); | 74 show(); |
76 } | 75 } |
77 | 76 |
78 function reset() { | 77 function reset() { |
79 localStorage.removeItem('start'); | 78 localStorage.removeItem('start'); |
80 localStorage.removeItem('stop'); | 79 localStorage.removeItem('stop'); |
81 showTime(); | 80 show(); |
82 fixButtons(); | |
83 } | 81 } |
84 | 82 |
85 function loaded() { | 83 function loaded() { |
86 showTime(); | 84 show(); |
87 fixButtons(); | 85 setInterval(show,1000); |
88 setInterval(showTime,1000); | |
89 } | 86 } |
90 | 87 |
91 </script> | 88 </script> |
92 </head> | 89 </head> |
93 <body onload="loaded()"> | 90 <body onload="loaded()"> |