mirror of
https://github.com/MapMakersAndProgrammers/wiki.git
synced 2025-10-26 09:59:10 -07:00
Deployed 2db1ea4 with MkDocs version: 1.6.1
This commit is contained in:
35
javascripts/extra.js
Normal file
35
javascripts/extra.js
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user