mirror of
https://github.com/thomasjsn/hugo-theme-hello-friend.git
synced 2024-11-24 16:55:07 +01:00
0be313316f
- Switch to the Hugo Pipes (bye bye Webpack) - Use Inter from Google Fonts - Update README
19 lines
528 B
JavaScript
19 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",
|
|
);
|
|
});
|