weko/assets/js/main.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

import obfuscates from 'js/obfuscates';
2021-06-12 01:58:10 +02:00
obfuscates();
2021-06-12 01:58:10 +02:00
function changeTheme() {
// https://css-tricks.com/a-complete-guide-to-dark-mode-on-the-web/#using-javascript-local-storage
const btn = document.querySelector(".btn-toggle");
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
const currentTheme = localStorage.getItem("theme");
if (currentTheme == "dark") {
document.body.classList.toggle("dark-theme");
} else if (currentTheme == "light") {
document.body.classList.toggle("light-theme");
}
btn.addEventListener("click", function () {
if (prefersDarkScheme.matches) {
document.body.classList.toggle("light-theme");
var theme = document.body.classList.contains("light-theme")
? "light"
: "dark";
} else {
document.body.classList.toggle("dark-theme");
var theme = document.body.classList.contains("dark-theme")
? "dark"
: "light";
}
localStorage.setItem("theme", theme);
});
}
function main() {
obfuscates();
2021-06-12 01:58:10 +02:00
changeTheme();
}
main();