Spaces:
Running
Running
| // Dark/Light mode switcher | |
| const toggleBtn = document.getElementById('theme-toggle'); | |
| const body = document.body; | |
| function setTheme(mode) { | |
| if (mode === 'light') { | |
| body.classList.add('light-mode'); | |
| localStorage.setItem('theme', 'light'); | |
| } else { | |
| body.classList.remove('light-mode'); | |
| localStorage.setItem('theme', 'dark'); | |
| } | |
| } | |
| toggleBtn.addEventListener('click', () => { | |
| if (body.classList.contains('light-mode')) { | |
| setTheme('dark'); | |
| } else { | |
| setTheme('light'); | |
| } | |
| }); | |
| // Auto-load theme | |
| if (localStorage.getItem('theme') === 'light') { | |
| setTheme('light'); | |
| } | |