refactor theme.js

This commit is contained in:
Wonderfall 2022-07-29 16:15:22 +02:00
parent 2f3c140f80
commit b43431bd51
1 changed files with 6 additions and 3 deletions

View File

@ -1,8 +1,11 @@
// for now this is assuming default theme is set to dark
// will probably refactor in the future for much better handling
function loadPreferredTheme() {
if (localStorage.getItem("pref-theme") === "light") {
const preferredTheme = localStorage.getItem("pref-theme");
const isDarkTheme = document.body.classList.contains("dark");
if (preferredTheme === "light" && isDarkTheme) {
document.body.classList.remove('dark')
} else if (preferredTheme === "dark" && !isDarkTheme) {
document.body.classList.add('dark')
}
}