forked from nst-sdc/DevClub-Site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
32 lines (29 loc) · 1.04 KB
/
theme.js
File metadata and controls
32 lines (29 loc) · 1.04 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
// Theme Management
function initializeTheme() {
const themeSwitch = document.getElementById('theme-switch');
const body = document.body;
// Check for saved theme preference
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
body.classList.add('light-theme');
if (themeSwitch) themeSwitch.checked = true;
} else {
body.classList.add('dark-theme');
}
// Theme switch event listener
if (themeSwitch) {
themeSwitch.addEventListener('change', () => {
if (themeSwitch.checked) {
body.classList.remove('dark-theme');
body.classList.add('light-theme');
localStorage.setItem('theme', 'light');
} else {
body.classList.remove('light-theme');
body.classList.add('dark-theme');
localStorage.setItem('theme', 'dark');
}
});
}
}
// Initialize theme when the script loads
document.addEventListener('DOMContentLoaded', initializeTheme);