mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 16:31:52 +01:00
initial commit
This commit is contained in:
40
assets/js/appearance.js
Normal file
40
assets/js/appearance.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const sitePreference = document.documentElement.getAttribute("data-default-appearance");
|
||||
const userPreference = localStorage.getItem("appearance");
|
||||
|
||||
if ((sitePreference === "dark" && userPreference === null) || userPreference === "dark") {
|
||||
document.documentElement.classList.add("dark");
|
||||
}
|
||||
|
||||
if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
|
||||
if (
|
||||
window.matchMedia &&
|
||||
window.matchMedia("(prefers-color-scheme: dark)").matches &&
|
||||
userPreference !== "light"
|
||||
) {
|
||||
document.documentElement.classList.add("dark");
|
||||
}
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (event) => {
|
||||
if (event.matches) {
|
||||
document.documentElement.classList.add("dark");
|
||||
} else {
|
||||
document.documentElement.classList.remove("dark");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener("DOMContentLoaded", (event) => {
|
||||
const switcher = document.getElementById("appearance-switcher");
|
||||
if (switcher) {
|
||||
switcher.addEventListener("click", () => {
|
||||
document.documentElement.classList.toggle("dark");
|
||||
localStorage.setItem(
|
||||
"appearance",
|
||||
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
);
|
||||
});
|
||||
switcher.addEventListener("contextmenu", (event) => {
|
||||
event.preventDefault();
|
||||
localStorage.removeItem("appearance");
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user