fix(a11y): prevent disableImages FOUC

This commit is contained in:
ZhenShuo Leo
2025-08-05 17:02:53 +08:00
parent ade00547b3
commit 344f7de0da
2 changed files with 4 additions and 14 deletions

View File

@@ -144,7 +144,10 @@ window.A11yPanel = (() => {
};
if (getSettings().disableImages) {
FEATURES.disableImages.apply(true);
new MutationObserver(() => {
const img = document.getElementById("background-image");
if (img) img.style.display = "none";
}).observe(document, { childList: true, subtree: true });
}
if (document.readyState === "loading") {

View File

@@ -37,16 +37,3 @@ document.querySelectorAll("script[data-target-id]").forEach((script) => {
const disableBlur = settings.disableBlur || false;
setBackgroundBlur(targetId, scrollDivisor, disableBlur, isMenuBlur);
});
// Prevent disableImages FOUC
// Note: I tried putting this in a11y.js but it did not work, and placing it here prevents FOUC
(() => {
const settings = JSON.parse(localStorage.getItem("a11ySettings") || "{}");
if (settings.disableImages) {
document.querySelectorAll("script[data-image-id]").forEach((script) => {
const imageId = script.getAttribute("data-image-id");
const image = imageId && document.getElementById(imageId);
if (image) image.style.display = "none";
});
}
})();