diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/scripts/functionality/application-receipt.ts | 4 | ||||
| -rw-r--r-- | src/scripts/optimize.ts | 8 | ||||
| -rw-r--r-- | src/utils/modify-dom.ts | 32 | ||||
| -rw-r--r-- | src/utils/observe-dom.ts | 4 |
4 files changed, 21 insertions, 27 deletions
diff --git a/src/scripts/functionality/application-receipt.ts b/src/scripts/functionality/application-receipt.ts index 7fdf4d0..878b910 100644 --- a/src/scripts/functionality/application-receipt.ts +++ b/src/scripts/functionality/application-receipt.ts @@ -1,4 +1,4 @@ -const receiptFormElement = document.querySelector("#form_reprint_request") as HTMLElement; +const receiptFormElement = document.getElementById("form_reprint_request") as HTMLElement; receiptFormElement.removeAttribute("id"); receiptFormElement.removeAttribute("name"); receiptFormElement.removeAttribute("onsubmit"); @@ -10,7 +10,7 @@ let captchaElement = document.querySelector("#werter > div > div:nth-child(4)") if (captchaElement) { captchaElement = captchaElement!; - const captchaValueElement = document.querySelector("#captchaText") as HTMLInputElement; + const captchaValueElement = document.getElementById("captchaText") as HTMLInputElement; const captchaFieldElement = document.querySelector("[name=txtDrawText]") as HTMLInputElement; const removeCaptcha = () => { captchaFieldElement.value = captchaValueElement.value; diff --git a/src/scripts/optimize.ts b/src/scripts/optimize.ts index 4acf66f..8389c53 100644 --- a/src/scripts/optimize.ts +++ b/src/scripts/optimize.ts @@ -1,7 +1,7 @@ -import { modifyDOM, DOMModifier } from "@/utils/modify-dom"; +import { modifyDOM } from "@/utils/modify-dom"; modifyDOM([ - new DOMModifier("head > script:nth-child(34)", { src: null }), - new DOMModifier("head > script:nth-child(36)", { src: null, innerHTML: "$.prototype.nivoSlider = () => {};" }), - new DOMModifier("head > script:nth-child(43)", { src: null }) + ["head > script:nth-child(34)", { src: null }], + ["head > script:nth-child(36)", { src: null, innerHTML: "$.prototype.nivoSlider = () => {};" }], + ["head > script:nth-child(43)", { src: null }] ]); diff --git a/src/utils/modify-dom.ts b/src/utils/modify-dom.ts index da0944b..f08f7d9 100644 --- a/src/utils/modify-dom.ts +++ b/src/utils/modify-dom.ts @@ -1,41 +1,35 @@ import { observeDOM } from "@/utils/observe-dom"; -type Replacements = { - [key: string]: string | null +type DOMReplacements = { + innerHTML?: string; + [key: string]: string | undefined | null; }; -export class DOMModifier { - selector: string; - attributes: Replacements; - constructor(selector: string, attributes: Replacements) { - this.selector = selector; - this.attributes = attributes; - } -} +type DOMModificaitonRule = readonly [string, DOMReplacements]; -export const modifyDOM = (elements: (DOMModifier | null)[]) => { +export const modifyDOM = (modificationRules: (DOMModificaitonRule | null)[]) => { let count = 0; observeDOM(() => { - for (let i = 0; i < elements.length; i++) { - if (elements[i]) { - const element = document.querySelector(elements[i]!.selector) as HTMLElement | null; + for (let i = 0; i < modificationRules.length; i++) { + if (modificationRules[i]) { + const element = document.querySelector(modificationRules[i]![0]) as HTMLElement | null; if (element) { - const attributes = elements[i]!.attributes as any; + const attributes = modificationRules[i]![1] as DOMReplacements; if (attributes.innerHTML) { - element.innerHTML = attributes.innerHTML; + element.innerHTML = attributes.innerHTML as string; } delete attributes.innerHTML; for (const attribute in attributes) { if (attributes[attribute] === null) { element.removeAttribute(attribute); } else { - element.setAttribute(attribute, attributes[attribute]); + element.setAttribute(attribute, attributes[attribute] as string); } } - elements[i] = null; + modificationRules[i] = null; count++; - if (count >= elements.length) { + if (count >= modificationRules.length) { return true; } } diff --git a/src/utils/observe-dom.ts b/src/utils/observe-dom.ts index 8ea1a98..4a447a0 100644 --- a/src/utils/observe-dom.ts +++ b/src/utils/observe-dom.ts @@ -1,11 +1,11 @@ -export const observeDOM = (callback: () => boolean, element: HTMLElement = document as unknown as HTMLElement) => { +export const observeDOM = (callback: () => boolean) => { const observer = new MutationObserver(() => { if (callback()) { observer.disconnect(); } }); - observer.observe(element, { + observer.observe(document, { childList: true, subtree: true }); |
