hugo-theme-wondermod/assets/js/theme.js

12 lines
396 B
JavaScript
Raw Normal View History

2022-07-22 00:00:36 +02:00
function loadPreferredTheme() {
2022-07-29 16:15:22 +02:00
const preferredTheme = localStorage.getItem("pref-theme");
const isDarkTheme = document.body.classList.contains("dark");
if (preferredTheme === "light" && isDarkTheme) {
2022-07-22 00:00:36 +02:00
document.body.classList.remove('dark')
2022-07-29 16:15:22 +02:00
} else if (preferredTheme === "dark" && !isDarkTheme) {
document.body.classList.add('dark')
2022-07-22 00:00:36 +02:00
}
}
loadPreferredTheme();