-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (34 loc) · 817 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var interval = 0;
function savetolocalstrage(currentTime)
{
localStorage.setItem('time',currentTime)
}
if(!localStorage.getItem('time'))
{
savetolocalstrage(0);
}
else{
interval = parseInt((localStorage.getItem('time')))
}
setInterval(function()
{
interval++
savetolocalstrage(interval)
if( interval === 100 || interval > 100 )
{
interval = 0
} else
{
$('#timer').text(toHHMMSS(interval));
}
}, 1000);
var toHHMMSS = (secs) => {
var sec_num = parseInt(secs, 10)
var hours = Math.floor(sec_num / 3600)
var minutes = Math.floor(sec_num / 60) % 60
var seconds = sec_num % 60
return [hours,minutes,seconds]
.map(v => v < 10 ? "0" + v : v)
.filter((v,i) => v !== "00" || i > 0)
.join(":")
}