-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
77 lines (69 loc) · 2.56 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
let minutesDown = "";
let secondsDown = "";
let lateMessage = "";
let timerInterval = {};
let hoursDown="";
function updateTimeDown(hours, minutes, seconds) {
let userLabel = document.getElementById("count-down-timer").innerText;
let currentLabel = document.getElementById("down-timer-label").value;
if (seconds == 0 && userLabel == currentLabel) {
if (minutes == 0 && userLabel == currentLabel) {
minutes = 0;
document.getElementById("count-down-timer").innerText = lateMessage;
seconds = (seconds / 1) - 1;
} else {
minutes = (minutes / 1) - 1;
seconds = 59;
}
} else if (seconds == -59) {
minutes = (minutes / 1) - 1;
seconds = 0;
} else {
minutes = (minutes / 1);
seconds = (seconds / 1) - 1;
}
//console.log("Down:" + minutes + ":" + seconds);
document.getElementById("minutes-down").innerText = minutes;
document.getElementById("seconds-down").innerText = seconds;
if (minutes == -60) {
for (i = 0; i < 100; i++) {
window.clearInterval(i);
document.getElementById("count-down-timer").innerText = "";
document.getElementById("seconds-down").innerText="00";
document.getElementById("minutes-down").innerText="00";
}
}
return ({
hours,
minutes,
seconds
});
}
function updateTimer() {
//console.log("upateTimer");
let returnedTime = updateTimeDown(hoursDown, minutesDown, secondsDown);
hoursDown = returnedTime.hours;
minutesDown = returnedTime.minutes;
secondsDown = returnedTime.seconds;
if (minutesDown == 0 && secondsDown == 0) {
stopTimer();
document.getElementById("totalMinutes").value =0;
setTimeout(runTimer, document.getElementById("grace-period").value * 1000);
}
}
function runTimer() {
if (timerInterval) {
stopTimer();
}
document.getElementById("minutes-down").innerText = document.getElementById("totalMinutes").value;
document.getElementById("count-down-timer").innerText = document.getElementById("down-timer-label").value;
minutesDown = document.getElementById("minutes-down").innerText;
secondsDown = document.getElementById("seconds-down").innerText;
lateMessage = document.getElementById("late-message").value;
timerInterval = setInterval(updateTimer, 1000);
}
function stopTimer() {
clearInterval(timerInterval);
document.getElementById("minutes-down").innerText = 0;
document.getElementById("seconds-down").innerText = 0;
}