Dark mode is now sticky.
This commit is contained in:
parent
7c19c6e72e
commit
0722f0bca0
1 changed files with 10 additions and 0 deletions
|
@ -18,6 +18,14 @@
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
// Select button
|
// Select button
|
||||||
const btn = document.querySelector(".theme-toggle");
|
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
|
// Listen for a click on the button
|
||||||
btn.addEventListener("click", function() {
|
btn.addEventListener("click", function() {
|
||||||
|
@ -25,8 +33,10 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
var theme = document.querySelector("#theme-link");
|
var theme = document.querySelector("#theme-link");
|
||||||
if (theme.getAttribute("href") == "/static/css/screen-light.css") {
|
if (theme.getAttribute("href") == "/static/css/screen-light.css") {
|
||||||
theme.href = "/static/css/screen-dark.css";
|
theme.href = "/static/css/screen-dark.css";
|
||||||
|
localStorage.setItem("theme", "dark");
|
||||||
} else {
|
} else {
|
||||||
theme.href = "/static/css/screen-light.css";
|
theme.href = "/static/css/screen-light.css";
|
||||||
|
localStorage.setItem("theme", "light");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue