playground.shiny.space/dark-mode.js
Lucas 7a4fa4b312 Fix dark mode flash by inlining critical script
- Move dark mode detection to inline script in HTML head
- Prevents white flash in Firefox by applying theme before render
- Clean up redundant code in dark-mode.js
- Apply fix to all HTML pages for consistent behavior

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-14 04:09:18 +02:00

27 lines
No EOL
860 B
JavaScript

// Dark mode toggle functionality
function toggleDarkMode() {
const html = document.documentElement;
const button = document.querySelector('.dark-mode-toggle');
if (html.getAttribute('data-theme') === 'dark') {
html.removeAttribute('data-theme');
button.textContent = '🌙';
localStorage.setItem('theme', 'light');
} else {
html.setAttribute('data-theme', 'dark');
button.textContent = '☀️';
localStorage.setItem('theme', 'dark');
}
}
// Load saved theme on page load
document.addEventListener('DOMContentLoaded', function() {
const savedTheme = localStorage.getItem('theme');
const button = document.querySelector('.dark-mode-toggle');
if (savedTheme === 'dark') {
button.textContent = '☀️';
} else {
button.textContent = '🌙';
}
});