-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
62 lines (54 loc) · 1.64 KB
/
timer.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var start = 0;
var end = 0;
var diff = 0;
var timerID = 0;
function chrono() {
end = new Date();
diff = end - start;
diff = new Date(diff);
var msec = diff.getMilliseconds();
var sec = diff.getSeconds();
var min = diff.getMinutes();
var hr = diff.getHours() - 1;
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
if (msec < 10) {
msec = "00" + msec;
}
else if (msec < 100) {
msec = "0" + msec;
}
document.getElementById("timer").innerHTML = (hr > 0 ? hr + ":" : "") + min + ":" + sec + "." + msec;
timerID = setTimeout("chrono()", 10);
}
function chronoStart() {
document.getElementById("btnPauze").disabled = "";
document.getElementById("btnStart").innerHTML = "Stop";
document.getElementById("btnStart").onclick = chronoStop;
start = new Date();
chrono();
}
function chronoPauze() {
document.getElementById("btnContinue").disabled = "";
document.getElementById("btnPauze").disabled = "disabled";
clearTimeout(timerID);
}
function chronoContinue() {
document.getElementById("btnContinue").disabled = "disabled";
document.getElementById("btnPauze").disabled = "";
start = new Date() - diff;
start = new Date(start);
chrono();
}
function chronoStop() {
document.getElementById("btnStart").innerHTML = "Start";
document.getElementById("btnStart").onclick = chronoStart;
document.getElementById("timer").innerHTML = "00:00.000";
document.getElementById("btnContinue").disabled = "disabled";
document.getElementById("btnPauze").disabled = "disabled";
clearTimeout(timerID);
}