Skip to content

Commit 033bdfe

Browse files
committed
setTheme in head scripts improved
1 parent ecd0793 commit 033bdfe

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/partials/head-scripts.hbs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
<script>var uiRootPath = '{{{uiRootPath}}}'</script>
1717

1818
<script>
19-
const setTheme = () => {
19+
function setTheme() {
2020
var localStorage = window.localStorage.getItem("themePreference");
2121
var systemPreference = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2222
23-
if (!localStorage) {
23+
if (localStorage !== "dark" && localStorage !== "light") {
2424
document.documentElement.setAttribute("data-theme", systemPreference);
2525
document.documentElement.setAttribute("data-theme-system", true);
26+
window.localStorage.removeItem("themePreference");
2627
} else {
2728
document.documentElement.setAttribute("data-theme", localStorage);
2829
}
29-
}
30-
setTheme()
30+
};
31+
setTheme();
3132
</script>

0 commit comments

Comments
 (0)