forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timers.js
38 lines (29 loc) · 1.08 KB
/
timers.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
let intervalKeeperMap = {};
let intervalsThatAreDone = [];
function startTimer(elementId) {
if(
Object.keys(intervalKeeperMap).includes(elementId) ||
intervalsThatAreDone.includes(elementId)
) return;
const timerElement = document.getElementById(elementId);
const intervalKeeper = setInterval(() => {
const timerText = timerElement.innerText;
const [seconds, milliseconds] = timerText.split(":");
const secondsInteger = parseInt(seconds);
const millisInteger = parseInt(milliseconds);
if(millisInteger === 99) {
timerElement.innerText = `${secondsInteger + 1}:00`;
} else {
timerElement.innerText = `${secondsInteger}:${millisInteger + 1}`;
}
}, 10);
intervalKeeperMap[elementId] = intervalKeeper;
}
function handleExampleClick() {
}
function stopTimer(elementId) {
if(!Object.keys(intervalKeeperMap).includes(elementId)) return;
clearInterval(intervalKeeperMap[elementId]);
delete intervalKeeperMap[elementId];
intervalsThatAreDone.push(elementId);
}