-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (41 loc) · 1.27 KB
/
app.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
// DOM Elements
const darkButton = document.getElementById("dark");
const lightButton = document.getElementById("light");
const solarButton = document.getElementById("solar");
const body = document.body;
// Button Event Handlers
lightButton.onclick = () => {
body.classList.replace("dark" , "light");
localStorage.setItem("theme" , "light");
}
darkButton.onclick = () => {
body.classList.replace("light" , "dark");
localStorage.setItem("theme" , "dark");
}
const solar_theme = () => {
if(body.classList.contains("solar")){
body.classList.remove("solar");
solarButton.style.cssText = `
--bg-solar: var(--yellow);
`;
solarButton.innerText = "Solarize";
localStorage.removeItem("isSolar"); }
else{
body.classList.add("solar");
solarButton.style.cssText = `
--bg-solar: var(--blue);
`;
solarButton.innerText = "Normalize";
localStorage.setItem("isSolar" , true);
}
}
solarButton.onclick = solar_theme;
// Apply cached items on reload
const theme = localStorage.getItem("theme");
const isSolar = localStorage.getItem("isSolar");
if(theme){
body.classList.add(theme);
if(isSolar){
solar_theme();
}
}