🐛 fix(theme-switcher): match functionality of minified and non-minified files

main
welpo 1 year ago
parent 130aa51144
commit ee2b171fbd
No known key found for this signature in database
GPG Key ID: A2F978CF4EC1F5A6

@ -5,7 +5,6 @@ const themeResetter = document.querySelector(".theme-resetter");
// Retrieve theme from either the localStorage or the data-theme attribute on the document element. // Retrieve theme from either the localStorage or the data-theme attribute on the document element.
let currentTheme = localStorage.getItem("theme") || document.documentElement.getAttribute('data-theme'); let currentTheme = localStorage.getItem("theme") || document.documentElement.getAttribute('data-theme');
// Function to set theme.
function setTheme(theme, saveToLocalStorage = false) { function setTheme(theme, saveToLocalStorage = false) {
document.documentElement.setAttribute("data-theme", theme); document.documentElement.setAttribute("data-theme", theme);
currentTheme = theme; currentTheme = theme;
@ -30,9 +29,7 @@ function setTheme(theme, saveToLocalStorage = false) {
} }
function resetTheme() { function resetTheme() {
const isSystemDark = window.matchMedia('(prefers-color-scheme: dark)').matches; setTheme(window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
const defaultTheme = isSystemDark ? "dark" : "light";
setTheme(defaultTheme);
} }
// Function to switch between dark and light themes. // Function to switch between dark and light themes.

Loading…
Cancel
Save