brainsteam.co.uk/new_files/js/main.js

46 lines
1.1 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function(){
var toggle = document.getElementById("scheme-toggle");
var scheme = "light";
var savedScheme = localStorage.getItem("scheme");
var container = document.getElementsByTagName("html")[0];
var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
if (prefersDark) {
scheme = "dark";
}
if(savedScheme) {
scheme = savedScheme;
}
if(scheme == "dark") {
darkscheme(toggle, container);
} else {
lightscheme(toggle, container);
}
toggle.addEventListener("click", () => {
if (toggle.className === "light") {
darkscheme(toggle, container);
} else if (toggle.className === "dark") {
lightscheme(toggle, container);
}
});
});
function darkscheme(toggle, container) {
localStorage.setItem("scheme", "dark");
toggle.innerHTML = feather.icons.sun.toSvg();
toggle.className = "dark";
container.className = "dark";
}
function lightscheme(toggle, container) {
localStorage.setItem("scheme", "light");
toggle.innerHTML = feather.icons.moon.toSvg();
toggle.className = "light";
container.className = "";
}