-
Notifications
You must be signed in to change notification settings - Fork 119
/
mode.js
25 lines (21 loc) · 842 Bytes
/
mode.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
const modeButton = document.getElementById('mode-button');
const sunIcon = document.getElementById('sun-icon');
const moonIcon = document.getElementById('moon-icon');
const currentMode = localStorage.getItem('mode');
if (currentMode) {
document.body.classList.toggle('dark', currentMode === 'dark');
sunIcon.style.display = currentMode === 'dark' ? 'inline' : 'none';
moonIcon.style.display = currentMode === 'dark' ? 'none' : 'inline';
}
modeButton.addEventListener('click', () => {
document.body.classList.toggle('dark');
if (document.body.classList.contains('dark')) {
sunIcon.style.display = 'inline';
moonIcon.style.display = 'none';
localStorage.setItem('mode', 'dark');
} else {
sunIcon.style.display = 'none';
moonIcon.style.display = 'inline';
localStorage.setItem('mode', 'light');
}
});