This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
57 lines (44 loc) · 1.78 KB
/
main.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
// Elements and variables
const dateLabel = document.querySelector("#date");
const separator = document.querySelectorAll(".separator");
const hourLabel = document.querySelector("#hour");
const minuteLabel = document.querySelector("#minute");
const secondLabel = document.querySelector("#second");
const secondsBar = document.querySelector("#seconds-bar");
const secondsProgress = document.querySelector("#seconds-progress");
// Everlasting Loop Function
function loop() {
let now = new Date();
dateLabel.innerHTML = now.toDateString();
// Blink every second
separator.forEach(i => {
i.style.opacity = `${(1000 - (now.getMilliseconds() % 1000)) / 1000}`;
});
// Display time
hourLabel.innerHTML = now.getHours().toString().padStart(2, "0");
minuteLabel.innerHTML = now.getMinutes().toString().padStart(2, "0");
secondLabel.innerHTML = now.getSeconds().toString().padStart(2, "0");
secondsProgress.style.width = `${((now.getSeconds() * 1000 + now.getMilliseconds()) / 600)}%`;
// Progress bar logic
switch (now.getMinutes() % 4) {
case 0:
secondsBar.style.background = "var(--bar-color-1)";
secondsProgress.style.background = "var(--bar-color-2)";
break;
case 1:
secondsBar.style.background = "var(--bar-color-2)";
secondsProgress.style.background = "var(--bar-color-3)";
break;
case 2:
secondsBar.style.background = "var(--bar-color-3)";
secondsProgress.style.background = "var(--bar-color-4)";
break;
case 3:
secondsBar.style.background = "var(--bar-color-4)";
secondsProgress.style.background = "var(--bar-color-1)";
break;
}
requestAnimationFrame(loop);
}
// Init
loop();