From de360c4ca4dfd7a164d5ed703a841db1b43a0501 Mon Sep 17 00:00:00 2001 From: Morpheus0x Date: Fri, 26 Aug 2022 14:58:00 +0200 Subject: [PATCH] Fixed first time theme change from dark mode If the theme is detected as dark, the first click on the toggle theme button will now change to light mode. Preveously no change would occur, since it would switch from default dark to force dark mode. --- assets/js/main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/js/main.js b/assets/js/main.js index dc302a1..811c5ba 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -27,8 +27,14 @@ function detectOSColorTheme() { function switchTheme(e) { if (chosenThemeIsDark) { localStorage.setItem("theme", "light"); - } else { + } else if (chosenThemeIsLight) { localStorage.setItem("theme", "dark"); + } else { + if (document.documentElement.getAttribute("data-theme") == "dark") { + localStorage.setItem("theme", "light"); + } else { + localStorage.setItem("theme", "dark"); + } } detectOSColorTheme();