-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (23 loc) · 686 Bytes
/
script.js
File metadata and controls
26 lines (23 loc) · 686 Bytes
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
const toggle = document.getElementById("dayNightToggle");
const body = document.body;
function setByTime() {
const hour = new Date().getHours();
if (hour >= 18 || hour < 6) {
toggle.classList.add("night");
body.classList.remove("light-mode");
body.classList.add("dark-mode");
} else {
toggle.classList.remove("night");
body.classList.remove("dark-mode");
body.classList.add("light-mode");
}
}
// Manual toggle
toggle.addEventListener("click", () => {
toggle.classList.toggle("night");
body.classList.toggle("dark-mode");
body.classList.toggle("light-mode");
});
// Auto set on load + keep updating
setByTime();
// setInterval(setByTime, 60000);