-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
46 lines (39 loc) · 1.33 KB
/
script.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
const deg = 6;
const hour = document.querySelector(".hour");
const min = document.querySelector(".min");
const sec = document.querySelector(".sec");
const setClock = () => {
let day = new Date();
let hh = day.getHours() * 30;
let mm = day.getMinutes() * deg;
let ss = day.getSeconds() * deg;
hour.style.transform = `rotateZ(${hh + mm / 12}deg)`;
min.style.transform = `rotateZ(${mm}deg)`;
sec.style.transform = `rotateZ(${ss}deg)`;
};
// first time
setClock();
// Update every 1000 ms
setInterval(setClock, 1000);
const switchTheme = (evt) => {
const switchBtn = evt.target;
if (switchBtn.textContent.toLowerCase() === "light") {
switchBtn.textContent = "dark";
// localStorage.setItem("theme", "dark");
document.documentElement.setAttribute("data-theme", "dark");
} else {
switchBtn.textContent = "light";
// localStorage.setItem("theme", "light"); //add this
document.documentElement.setAttribute("data-theme", "light");
}
};
const switchModeBtn = document.querySelector(".switch-btn");
switchModeBtn.addEventListener("click", switchTheme, false);
let currentTheme = "dark";
// currentTheme = localStorage.getItem("theme")
// ? localStorage.getItem("theme")
// : null;
if (currentTheme) {
document.documentElement.setAttribute("data-theme", currentTheme);
switchModeBtn.textContent = currentTheme;
}