forked from GitSquared/edex-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.class.js
More file actions
45 lines (39 loc) · 1.35 KB
/
Copy pathclock.class.js
File metadata and controls
45 lines (39 loc) · 1.35 KB
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
class Clock {
constructor(parentId) {
if (!parentId) throw "Missing parameters";
// Create DOM
this.parent = document.getElementById(parentId);
this.parent.innerHTML += `<div id="mod_clock">
<h1 id="mod_clock_text"><span>?</span><span>?</span><span>:</span><span>?</span><span>?</span><span>:</span><span>?</span><span>?</span></h1>
</div>`;
this.lastTime = new Date();
this.updateClock();
this.updater = setInterval(() => {
this.updateClock();
}, 1000);
}
updateClock() {
let time = new Date();
let array = [time.getHours(), time.getMinutes(), time.getSeconds()];
if (this.lastTime.getMinutes() !== array[1]) {
window.audioManager.beep5.play();
}
array.forEach((e, i) => {
if (e.toString().length !== 2) {
array[i] = "0"+e;
}
});
let clockString = `${array[0]}:${array[1]}:${array[2]}`;
array = clockString.match(/.{1}/g);
clockString = "";
array.forEach((e) => {
if (e === ":") clockString += "<em>"+e+"</em>";
else clockString += "<span>"+e+"</span>";
});
document.getElementById("mod_clock_text").innerHTML = clockString;
this.lastTime = time;
}
}
module.exports = {
Clock
};