mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-01-23 06:55:43 -06:00
67 lines
No EOL
2.1 KiB
JavaScript
67 lines
No EOL
2.1 KiB
JavaScript
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");
|
|
const switcherMobile = document.getElementById("appearance-switcher-mobile");
|
|
|
|
updateMeta()
|
|
|
|
if (switcher) {
|
|
switcher.addEventListener("click", () => {
|
|
document.documentElement.classList.toggle("dark");
|
|
localStorage.setItem(
|
|
"appearance",
|
|
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
|
);
|
|
updateMeta()
|
|
});
|
|
switcher.addEventListener("contextmenu", (event) => {
|
|
event.preventDefault();
|
|
localStorage.removeItem("appearance");
|
|
});
|
|
}
|
|
if (switcherMobile) {
|
|
switcherMobile.addEventListener("click", () => {
|
|
document.documentElement.classList.toggle("dark");
|
|
localStorage.setItem(
|
|
"appearance",
|
|
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
|
);
|
|
updateMeta()
|
|
});
|
|
switcherMobile.addEventListener("contextmenu", (event) => {
|
|
event.preventDefault();
|
|
localStorage.removeItem("appearance");
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
var updateMeta = () => {
|
|
var elem, style;
|
|
elem = document.querySelector('body');
|
|
style = getComputedStyle(elem);
|
|
document.querySelector('meta[name="theme-color"]').setAttribute('content', style.backgroundColor);
|
|
} |