-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (38 loc) · 1.2 KB
/
app.js
File metadata and controls
51 lines (38 loc) · 1.2 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
// DOM Elements
const darkButton = document.getElementById("dark");
const lightButton = document.getElementById("light");
const solarButton = document.getElementById("solar");
const body = document.body;
// Apply the cached theme on reload
const theme = localStorage.getItem("theme");
const isSolar = localStorage.getItem("isSolar");
if (theme) {
body.classList.add(theme);
isSolar && body.classList.add("solar");
}
// Button Evenet Handlers
darkButton.onclick = () => {
// body.classList.remove("light");
// body.classList.add("dark");
body.classList.replace("light", "dark");
localStorage.setItem("theme", "dark");
};
lightButton.onclick = () => {
body.classList.replace("dark", "light");
localStorage.setItem("theme", "light");
};
solarButton.onclick = () => {
if (body.classList.contains("solar")) {
body.classList.remove("solar");
solarButton.style.cssText = `
--bg-solar: var(--yellow);`;
solarButton.innerText = "solarize";
localStorage.removeItem("isSolar");
} else {
solarButton.style.cssText = `
--bg-solar: orangered;`;
body.classList.add("solar");
solarButton.innerText = "normalize";
localStorage.setItem("isSolar", true);
}
};