Spaces:
Running
Running
| // Initialize app | |
| document.addEventListener('DOMContentLoaded', () => { | |
| // Check for saved theme preference | |
| const savedTheme = localStorage.getItem('theme'); | |
| if (savedTheme) { | |
| document.documentElement.classList.add(savedTheme); | |
| } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { | |
| document.documentElement.classList.add('dark'); | |
| } | |
| // Smooth transitions | |
| setTimeout(() => { | |
| document.body.classList.remove('opacity-0'); | |
| }, 100); | |
| }); | |
| // Theme toggle functionality | |
| function toggleTheme() { | |
| const html = document.documentElement; | |
| if (html.classList.contains('dark')) { | |
| html.classList.remove('dark'); | |
| localStorage.setItem('theme', 'light'); | |
| } else { | |
| html.classList.add('dark'); | |
| localStorage.setItem('theme', 'dark'); | |
| } | |
| } |