document.addEventListener('DOMContentLoaded', function() { const themeToggle = document.getElementById('theme-toggle'); if (!themeToggle) { return; } themeToggle.addEventListener('click', function(e) { e.preventDefault(); // Get current theme from html element const htmlElement = document.documentElement; const isDark = htmlElement.classList.contains('theme-dark'); const newTheme = isDark ? 'light' : 'dark'; // Remove both theme classes htmlElement.classList.remove('theme-light', 'theme-dark'); // Add the new theme class htmlElement.classList.add(`theme-${newTheme}`); // Update article type badge colors const badges = document.querySelectorAll('[data-theme-dark-color]'); badges.forEach(badge => { if (newTheme === 'dark') { const darkColor = badge.getAttribute('data-theme-dark-color'); badge.style.color = darkColor; badge.style.backgroundColor = darkColor + '20'; } else { const lightColor = badge.style.color; // Already set to light in HTML badge.style.color = lightColor; // backgroundColor stays as is (light color with opacity) } }); // Persist to localStorage localStorage.setItem('theme', newTheme); // Update Feather Icons if available if (window.feather) { window.feather.replace(); } }); });