diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-12 06:43:51 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-12 06:43:51 +0530 |
| commit | a6f62616b7c10092451cb2b7d6ed5c7c5b250712 (patch) | |
| tree | 785456fbe40cb256c1cdcf8eb5b5e67e06c31d95 /src/scripts | |
| parent | 1caecf35a2d0ee81cedea40ccbd4ad4150bca2f8 (diff) | |
| download | banglar-bhumi-utils-a6f62616b7c10092451cb2b7d6ed5c7c5b250712.tar.gz banglar-bhumi-utils-a6f62616b7c10092451cb2b7d6ed5c7c5b250712.zip | |
Added home page optimizations.
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]); } |
