diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-14 09:46:34 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-14 09:46:34 +0530 |
| commit | a30b28d40e5bacdbbbcad3c9de8f1fe3e083119c (patch) | |
| tree | c2f367c5ea4179911a0c2d279a2e980a96414d26 /src/scripts/optimize | |
| parent | 34ad953c953a395ba3e51c8125034a6bb65b2a79 (diff) | |
| download | banglar-bhumi-utils-a30b28d40e5bacdbbbcad3c9de8f1fe3e083119c.tar.gz banglar-bhumi-utils-a30b28d40e5bacdbbbcad3c9de8f1fe3e083119c.zip | |
Added ability to load static assets from extension's assets.
Diffstat (limited to 'src/scripts/optimize')
| -rw-r--r-- | src/scripts/optimize/home-page.ts | 35 | ||||
| -rw-r--r-- | src/scripts/optimize/index.ts | 37 |
2 files changed, 11 insertions, 61 deletions
diff --git a/src/scripts/optimize/home-page.ts b/src/scripts/optimize/home-page.ts index 2affea7..4c1f21f 100644 --- a/src/scripts/optimize/home-page.ts +++ b/src/scripts/optimize/home-page.ts @@ -1,32 +1,7 @@ -import observeDOM from "@/utils/observe-dom"; +import { replaceAttributes } from "@/utils/replace-attributes"; -const replace: (any[] | undefined)[] = [ - ["#slider > img", { src: "" }], - ["#slider > img.nivo-main-image", { src: "" }] -]; -let count = 0; +const bannerImageUrl = chrome.runtime.getURL("assets/banner.jpg"); -observeDOM(() => { - 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) { - return true; - } - } - } - } - - return false; -}); +replaceAttributes([ + ["#form_MainMenuPage > div > div:nth-child(13)", { innerHTML: `<img src="${bannerImageUrl}" style="width: 100vw" />` }] +]); diff --git a/src/scripts/optimize/index.ts b/src/scripts/optimize/index.ts index 37ae12e..70cbac3 100644 --- a/src/scripts/optimize/index.ts +++ b/src/scripts/optimize/index.ts @@ -1,32 +1,7 @@ -import observeDOM from "@/utils/observe-dom"; +import { replaceAttributes } from "@/utils/replace-attributes"; -const replace: (any[] | undefined)[] = [ - ["head > script:nth-child(34)", { src: "" }], - ["head > script:nth-child(43)", { src: "" }] -]; -let count = 0; - -observeDOM(() => { - 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) { - return true; - } - } - } - } - - return false; -}); +replaceAttributes([ + ["head > script:nth-child(34)", { src: null }], + ["head > script:nth-child(36)", { src: null, innerHTML: "$.prototype.nivoSlider = () => {};" }], + ["head > script:nth-child(43)", { src: null }] +]); |
