diff options
Diffstat (limited to 'src/scripts')
| -rw-r--r-- | src/scripts/optimize/home-page.ts | 30 | ||||
| -rw-r--r-- | src/scripts/optimize/index.ts (renamed from src/scripts/optimize.ts) | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/scripts/optimize/home-page.ts b/src/scripts/optimize/home-page.ts new file mode 100644 index 0000000..5ca4c2e --- /dev/null +++ b/src/scripts/optimize/home-page.ts @@ -0,0 +1,30 @@ +const replace: (any[] | undefined)[] = [ + ["#slider > img", { src: "" }], + ["#slider > img.nivo-main-image", { src: "" }] +]; +let count = 0; + +const observer = new MutationObserver(() => { + for (let i = 0; i < replace.length; i++) { + if (replace[i]) { + const element = document.querySelector(replace[i]![0]) as HTMLElement | null; + if (element) { + const attributes = replace[i]![1]; + if (attributes.innerHTML) { + element.innerHTML = attributes.innerHTML; + } + delete attributes.innerHTML; + for (const attribute in attributes) { + element.setAttribute(attribute, attributes[attribute]); + } + replace[i] = undefined; + count++; + if (count >= replace.length) { + observer.disconnect(); + break; + } + } + } + } +}); +observer.observe(document, {childList: true, subtree: true}); diff --git a/src/scripts/optimize.ts b/src/scripts/optimize/index.ts index 3994333..8b63c53 100644 --- a/src/scripts/optimize.ts +++ b/src/scripts/optimize/index.ts @@ -13,7 +13,7 @@ const observer = new MutationObserver(() => { if (attributes.innerHTML) { element.innerHTML = attributes.innerHTML; } - attributes.innerHTML = undefined; + delete attributes.innerHTML; for (const attribute in attributes) { element.setAttribute(attribute, attributes[attribute]); } |
