hugo-theme-hello-friend/assets/js/theme.js
panr 0be313316f Init version 2
- Switch to the Hugo Pipes (bye bye Webpack)
- Use Inter from Google Fonts
- Update README
2020-08-09 00:43:49 +02:00

18 lines
528 B
JavaScript

// Toggle theme
const getTheme = window.localStorage && window.localStorage.getItem("theme");
const themeToggle = document.querySelector(".theme-toggle");
const isDark = getTheme === "dark";
if (getTheme !== null) {
document.body.classList.toggle("dark-theme", isDark);
}
themeToggle.addEventListener("click", () => {
document.body.classList.toggle("dark-theme");
window.localStorage &&
window.localStorage.setItem(
"theme",
document.body.classList.contains("dark-theme") ? "dark" : "light",
);
});