mirror of
https://github.com/OrcaSlicer/OrcaSlicer_WIKI.git
synced 2026-05-17 00:25:45 +03:00
Introduces web_extras/icon-theme.js to handle dynamic icon switching based on theme. Updates build scripts (build.ps1, build.sh) to copy custom CSS and JS assets for both docs and wiki outputs. mkdocs.yml is updated to include the new JS asset and reorganizes the Print Prepare navigation for clarity.
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
(function () {
|
|
const tracked = new Set();
|
|
|
|
const ensureTracked = (img) => {
|
|
if (img.dataset.lightSrc && img.dataset.darkSrc) {
|
|
tracked.add(img);
|
|
return;
|
|
}
|
|
|
|
const src = img.getAttribute('src') || '';
|
|
const match = src.match(/^(.*)_dark(\.svg(?:\?.*)?)$/i);
|
|
if (!match) return;
|
|
|
|
img.dataset.darkSrc = src;
|
|
img.dataset.lightSrc = `${match[1]}${match[2]}`;
|
|
tracked.add(img);
|
|
};
|
|
|
|
const applyTheme = () => {
|
|
const dark = (document.body?.dataset?.mdColorScheme || '').toLowerCase() === 'slate';
|
|
tracked.forEach((img) => {
|
|
const target = dark ? img.dataset.darkSrc : img.dataset.lightSrc;
|
|
if (target && img.getAttribute('src') !== target) {
|
|
img.setAttribute('src', target);
|
|
}
|
|
});
|
|
};
|
|
|
|
const refresh = () => {
|
|
document.querySelectorAll('img').forEach(ensureTracked);
|
|
applyTheme();
|
|
};
|
|
|
|
const onReady = () => refresh();
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', onReady, { once: true });
|
|
} else {
|
|
onReady();
|
|
}
|
|
|
|
if (window.document$ && typeof window.document$.subscribe === 'function') {
|
|
window.document$.subscribe(onReady);
|
|
}
|
|
|
|
const observer = new MutationObserver((mutations) => {
|
|
if (mutations.some((m) => m.attributeName === 'data-md-color-scheme')) {
|
|
applyTheme();
|
|
}
|
|
});
|
|
|
|
if (document.body) {
|
|
observer.observe(document.body, { attributes: true, attributeFilter: ['data-md-color-scheme'] });
|
|
}
|
|
})();
|