1159cl/js/theme-toggle.js
Mario1159 5b6b79892c
Some checks failed
Release / test (push) Failing after 51s
Release / push-docker-image (push) Has been skipped
2024 new version
2024-12-06 20:38:18 -03:00

23 lines
811 B
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const themeToggle = document.getElementById('theme-toggle');
const themeIcon = document.getElementById('theme-icon');
function applyTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
themeIcon.src = theme === 'dark' ? 'icons/pixelarticons/svg/moon.svg' : 'icons/pixelarticons/svg/sun-alt.svg';
themeToggle.checked = theme === 'dark';
}
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
applyTheme(systemPrefersDark ? 'dark' : 'light');
themeToggle.addEventListener('change', function() {
if (this.checked) {
applyTheme('dark');
} else {
applyTheme('light');
}
});
});