
- 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>
27 lines
No EOL
860 B
JavaScript
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 = '🌙';
|
|
}
|
|
}); |