* Dark Mode + Theming * Themes scss file created with default color scheme and dark color scheme. * Logic for managing dark mode toggle added. * Modified existing scss/html to work with theme toggling. * Fixed hover issues * Added enable_darkmode to configs. * Added the requested option of disabling/enabling dark mode via config files.
18 lines
453 B
JavaScript
18 lines
453 B
JavaScript
//Has to be in the head tag, otherwise a flicker effect will occur.
|
|
let initTheme = (theme) => {
|
|
if (theme == null) {
|
|
const userPref = window.matchMedia;
|
|
if (userPref && userPref('(prefers-color-scheme: dark)').matches) {
|
|
theme = 'dark';
|
|
}
|
|
}
|
|
|
|
if (theme) {
|
|
document.documentElement.setAttribute('data-theme', theme)
|
|
}
|
|
|
|
localStorage.setItem("theme", theme);
|
|
}
|
|
|
|
initTheme(localStorage.getItem("theme"));
|