-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
64 lines (53 loc) · 1.28 KB
/
renderer.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
const timeEl = document.querySelector('time');
const btn = document.querySelector('button');
const msg = document.querySelector('.message');
const ding = document.querySelector('audio');
const timers = [
{
"duration": 1,
"message":"Sit"
},
{
"duration": 2,
"message":"Stand"
},
{
"duration": 3,
"message":"Move Around"
}
];
let intervalId;
function startTimer(duration, display) {
let timer = duration;
intervalId = setInterval(() => {
--timer;
let minutes = parseInt(timer / 60, 10);
let seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? `0${minutes}` : minutes;
seconds = seconds < 10 ? `0${seconds}` : seconds;
display.textContent = `${minutes}:${seconds}`;
if (minutes == 0 && seconds == 0) {
notifyUser();
}
}, 1000);
}
btn.addEventListener('click', clickHandler);
function clickHandler(){
if(timers.length){
startTimer(timers[0].duration * 60, timeEl);
msg.textContent = `Now ${timers[0].message} for ${timers[0].duration} minutes.`
}
// startTimer(1 * 60, timeEl);
btn.disabled = true;
}
function notifyUser() {
clearInterval(intervalId);
ding.play();
timers.shift();
console.log(timers);
if(!timers.length){
btn.disabled = null;
} else {
clickHandler();
}
}