diff --git a/app/static/js/main.js b/app/static/js/main.js index 76fdcf1..308ae6a 100644 --- a/app/static/js/main.js +++ b/app/static/js/main.js @@ -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"); } }); });