Files
wiki/docs/javascripts/extra.js
2025-01-29 07:49:44 +01:00

35 lines
1.1 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function() {
// Sync with Material's native storage key
const STORAGE_KEY = "md-color-scheme";
// Get initial theme state
const savedTheme = localStorage.getItem(STORAGE_KEY) || "default";
document.body.setAttribute("data-md-color-scheme", savedTheme);
// Watch for theme changes
const mutationObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.attributeName === "data-md-color-scheme") {
const currentTheme = document.body.getAttribute("data-md-color-scheme");
localStorage.setItem(STORAGE_KEY, currentTheme);
}
});
});
// Start observing body attributes
mutationObserver.observe(document.body, {
attributes: true,
attributeFilter: ["data-md-color-scheme"]
});
// Debounced click handler
let isToggling = false;
document.querySelector(".md-header__button[data-md-color-scheme]").addEventListener("click", () => {
if (!isToggling) {
isToggling = true;
setTimeout(() => {
isToggling = false;
}, 300);
}
});
});