Spaces:
Runtime error
Runtime error
Download frontend/theme.js from BugHu/voice-detector: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/BugHu/voice-detector/resolve/main/frontend/theme.js
- Command line
-
hf download hf://spaces/BugHu/voice-detector/frontend/theme.js
-
curl -L -o theme.js https://huggingface.co/spaces/BugHu/voice-detector/resolve/main/frontend/theme.js
1.84 kB
| /** | |
| * theme.js - Light/Dark Mode Logic | |
| * Handles theme switching, persistence, and UI synchronization. | |
| */ | |
| (function () { | |
| const THEME_KEY = 'ai_detector_theme'; | |
| // 1. Immediate Theme Application (to <html> to prevent flash) | |
| const savedTheme = localStorage.getItem(THEME_KEY) || 'light'; | |
| if (savedTheme === 'dark') { | |
| document.documentElement.classList.add('dark'); | |
| // We'll add it to body as well once DOM is ready | |
| } | |
| function initThemeToggle() { | |
| const body = document.body; | |
| const html = document.documentElement; | |
| // Sync body class with html/saved state | |
| if (savedTheme === 'dark') { | |
| body.classList.add('dark'); | |
| } | |
| const toggleBtn = document.getElementById('themeToggle'); | |
| if (toggleBtn) { | |
| const icon = toggleBtn.querySelector('i'); | |
| // Sync initial icon | |
| if (icon && body.classList.contains('dark')) { | |
| icon.classList.remove('fa-moon'); | |
| icon.classList.add('fa-sun'); | |
| } | |
| toggleBtn.addEventListener('click', () => { | |
| const isDark = body.classList.toggle('dark'); | |
| html.classList.toggle('dark', isDark); | |
| localStorage.setItem(THEME_KEY, isDark ? 'dark' : 'light'); | |
| // Toggle icon | |
| if (icon) { | |
| if (isDark) { | |
| icon.classList.replace('fa-moon', 'fa-sun'); | |
| } else { | |
| icon.classList.replace('fa-sun', 'fa-moon'); | |
| } | |
| } | |
| }); | |
| } | |
| } | |
| // Run when DOM is ready | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', initThemeToggle); | |
| } else { | |
| initThemeToggle(); | |
| } | |
| })(); | |