diff options
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 }] +]); |
