diff options
Diffstat (limited to 'src/scripts/optimize')
| -rw-r--r-- | src/scripts/optimize/home-page.ts | 30 | ||||
| -rw-r--r-- | src/scripts/optimize/index.ts | 30 |
2 files changed, 60 insertions, 0 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/index.ts b/src/scripts/optimize/index.ts new file mode 100644 index 0000000..8b63c53 --- /dev/null +++ b/src/scripts/optimize/index.ts @@ -0,0 +1,30 @@ +const replace: (any[] | undefined)[] = [ + ["head > script:nth-child(34)", { src: "" }], + ["head > script:nth-child(43)", { 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}); |
