Fix error in theme switcher

This commit is contained in:
Simon Detheridge 2023-10-16 19:55:08 +01:00
parent ab61ad1a67
commit a84195497e
Signed by: simon
GPG Key ID: 38640971DA1E704E
3 changed files with 8 additions and 5 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,6 +18,7 @@ function changeFavicon() {
} }
function changeTheme(useLight) { function changeTheme(useLight) {
console.log({ useLight })
document.documentElement.classList.remove('light-theme', 'dark-theme', 'has-light-text', 'has-dark-text') document.documentElement.classList.remove('light-theme', 'dark-theme', 'has-light-text', 'has-dark-text')
if (useLight) { if (useLight) {
document.documentElement.classList.add('light-theme', 'has-dark-text') document.documentElement.classList.add('light-theme', 'has-dark-text')
@ -28,7 +29,7 @@ function changeTheme(useLight) {
if (window.localStorage) { if (window.localStorage) {
window.localStorage.setItem( window.localStorage.setItem(
"lightTheme", "lightTheme",
useLight) useLight ? "light" : "dark")
} }
changeFavicon() changeFavicon()
@ -38,8 +39,10 @@ themeToggle.addEventListener("click", () => {
changeTheme(document.documentElement.classList.contains('dark-theme')) changeTheme(document.documentElement.classList.contains('dark-theme'))
}); });
if (localTheme instanceof Boolean) { console.log({ localTheme, isOSLight })
changeTheme(localTheme)
if (localTheme === "light") {
changeTheme(true)
} else { } else {
changeTheme(isOSLight) changeTheme(isOSLight)
} }