Mostly completed dark mode support

This commit is contained in:
2025-02-17 15:30:46 +01:00
parent b393b3cc55
commit 9df8fc5647
5 changed files with 42 additions and 30 deletions

View File

@@ -68,34 +68,7 @@
document.getElementById( 'analytics' ).classList.add( 'show' );
}
// Themeing
let loadedTheme = localStorage.getItem( 'theme' ) ?? 'auto';
var theme = loadedTheme;
let loadTheme = () => {
loadedTheme = localStorage.getItem( 'theme' ) ?? 'auto';
if ( loadedTheme === 'auto' ) {
if ( window.matchMedia( '(prefers-color-scheme: dark)' ).matches ) {
theme = 'dark_mode';
} else {
theme = 'light_mode';
}
}
if ( theme === 'dark_mode' ) {
document.documentElement.classList.remove( 'light' );
document.documentElement.classList.add( 'dark' );
} else {
document.documentElement.classList.add( 'light' );
document.documentElement.classList.remove( 'dark' );
theme === 'light_mode';
}
}
loadTheme();
// Show which theme is loaded
document.getElementById( 'theme-select' ).value = loadedTheme;
function changeTheme () {
theme = document.getElementById( 'theme-select' ).value;
localStorage.setItem( 'theme', theme );
loadTheme();
}
</script>
</div>