This commit is contained in:
Thomas Chartron 2021-11-06 12:51:33 +01:00
parent cdb1ae5c8f
commit c7b220f30d

View file

@ -11,8 +11,10 @@ document.addEventListener("DOMContentLoaded", function() {
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
document.getElementById('light').add('hidden');
} else {
document.documentElement.classList.remove('dark')
document.getElementById('dark').add('hidden');
}
// Switch theme action
document.getElementById('switch-theme').addEventListener('click', switchTheme);
@ -29,7 +31,7 @@ function switchTheme() {
} else {
localStorage.theme = 'dark';
document.documentElement.classList.add('dark');
document.getElementById('light').remove('hidden');
document.getElementById('dark').add('hidden');
document.getElementById('light').add('hidden');
document.getElementById('dark').remove('hidden');
}
}