-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
64 lines (52 loc) · 1.41 KB
/
Copy pathclock.js
File metadata and controls
64 lines (52 loc) · 1.41 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
let clockUpdateLoop;
let isShowSeconds;
let clockEvents;
clockEvents = {};
let lastEventCheckTime = "";
function checkForClockEvents() {
let d = new Date();
let timeString = pad(d.getHours(), 2) + ":"
+ pad(d.getMinutes(), 2) + ":" + pad(d.getSeconds(), 2);
let eventEntries = Object.entries(clockEvents).sort((a, b) => (a > b) ? 1 : ((a < b) ? -1 : 0));
let i = 0;
for (; i < eventEntries.length; i++) {
if (eventEntries[i][0] > lastEventCheckTime)
break;
}
for (; i < eventEntries.length; i++) {
if (eventEntries[i][0] > timeString)
break;
eventEntries[i][1]();
}
lastEventCheckTime = timeString;
}
function updateClock() {
let d = new Date();
let timeString = pad(d.getHours(), 2) + ":"
+ pad(d.getMinutes(), 2);
if (isShowSeconds) {
timeString += ":" + pad(d.getSeconds(), 2);
}
$("#clockValue")[0].innerText = timeString;
checkForClockEvents();
}
function setClockFontsize(points) {
$("#clockValue")[0].style.fontSize = `${points}pt`;
}
function startClock() {
stopClock();
clockUpdateLoop = setInterval(updateClock, 200);
}
function stopClock() {
if (clockUpdateLoop != null) {
clearInterval(clockUpdateLoop);
clockUpdateLoop = null;
}
}
function showSeconds() {
isShowSeconds = true;
}
function hideSeconds() {
isShowSeconds = false;
}