Dark mode is now sticky.

This commit is contained in:
Flancian 2020-11-15 02:24:44 +01:00
parent 7c19c6e72e
commit 0722f0bca0

View file

@ -18,6 +18,14 @@
document.addEventListener("DOMContentLoaded", function() {
// Select button
const btn = document.querySelector(".theme-toggle");
var theme = document.querySelector("#theme-link");
const currentTheme = localStorage.getItem("theme");
// If the user's preference in localStorage is dark...
if (currentTheme == "dark") {
theme.href = "/static/css/screen-dark.css";
} else if (currentTheme == "light") {
theme.href = "/static/css/screen-light.css";
}
// Listen for a click on the button
btn.addEventListener("click", function() {
@ -25,8 +33,10 @@ document.addEventListener("DOMContentLoaded", function() {
var theme = document.querySelector("#theme-link");
if (theme.getAttribute("href") == "/static/css/screen-light.css") {
theme.href = "/static/css/screen-dark.css";
localStorage.setItem("theme", "dark");
} else {
theme.href = "/static/css/screen-light.css";
localStorage.setItem("theme", "light");
}
});
});