feat: enhance theme toggle functionality with auto theme support and icon updates. Fix #243

This commit is contained in:
Will Miao
2025-06-21 20:43:44 +08:00
parent ba2e42b06e
commit c3dd4da11b
4 changed files with 62 additions and 7 deletions

View File

@@ -46,9 +46,21 @@ export class HeaderManager {
// Handle theme toggle
const themeToggle = document.querySelector('.theme-toggle');
if (themeToggle) {
// Set initial state based on current theme
const currentTheme = localStorage.getItem('lm_theme') || 'auto';
themeToggle.classList.add(`theme-${currentTheme}`);
themeToggle.addEventListener('click', () => {
if (typeof toggleTheme === 'function') {
toggleTheme();
const newTheme = toggleTheme();
// Update tooltip based on next toggle action
if (newTheme === 'light') {
themeToggle.title = "Switch to dark theme";
} else if (newTheme === 'dark') {
themeToggle.title = "Switch to auto theme";
} else {
themeToggle.title = "Switch to light theme";
}
}
});
}