-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (38 loc) · 1.13 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
51
52
53
54
55
56
// 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 Event Handlers
darkButton.onclick = () => {
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: white;
`
body.classList.add('solar');
solarButton.innerText = 'normalize';
localStorage.setItem('isSolar', true);
}
};