From 915947e3e7ab7c1fa07596ab4b13bf6e1cc50b76 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:51:39 +0530 Subject: Cleaned code. --- src/manifest.json | 15 --------------- src/scripts.json | 15 +++++++++++++++ src/scripts/block-unnecessary.ts | 35 +++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 29 deletions(-) delete mode 100644 src/manifest.json create mode 100644 src/scripts.json (limited to 'src') diff --git a/src/manifest.json b/src/manifest.json deleted file mode 100644 index 8e8d0bd..0000000 --- a/src/manifest.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "before": { - "block-unnecessary.ts": "*" - }, - "injected": { - "stop-blocking.js": "*" - }, - "injected_and_loaded": { - "autofill-otps.ts": "*", - "auto-login.ts": "*" - }, - "loaded": { - "autofill-captcha.ts": "*" - } -} diff --git a/src/scripts.json b/src/scripts.json new file mode 100644 index 0000000..8e8d0bd --- /dev/null +++ b/src/scripts.json @@ -0,0 +1,15 @@ +{ + "before": { + "block-unnecessary.ts": "*" + }, + "injected": { + "stop-blocking.js": "*" + }, + "injected_and_loaded": { + "autofill-otps.ts": "*", + "auto-login.ts": "*" + }, + "loaded": { + "autofill-captcha.ts": "*" + } +} diff --git a/src/scripts/block-unnecessary.ts b/src/scripts/block-unnecessary.ts index 4163778..bec90a5 100644 --- a/src/scripts/block-unnecessary.ts +++ b/src/scripts/block-unnecessary.ts @@ -1,23 +1,30 @@ -type ConditionalString = string | undefined; -let blocked: ConditionalString[] = [ - "head > script:nth-child(34)", - "head > script:nth-child(43)" +let replace: (any[] | undefined)[] = [ + ["head > script:nth-child(34)", { src: "" }], + ["head > script:nth-child(35)", { src: "https://code.jquery.com/jquery-1.12.4.min.js", crossorigin: "anonymous" }], + ["head > script:nth-child(43)", { src: "" }] ]; let count = 0; +let notDone = false; -const observer = new MutationObserver(mutations => { - for (let i = 0; i < blocked.length; i++) { - if (blocked[i]) { - const element = document.querySelector(blocked[i]!) as HTMLElement | null; +const observer = new MutationObserver(() => { + if (notDone) { + const meta = document.querySelector("head > meta:nth-child(2)"); + if (meta) { + meta.setAttribute("http-equiv", "Content-Security-Policy"); + meta.setAttribute("content", "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"); + } + } + for (let i = 0; i < replace.length; i++) { + if (replace[i]) { + const element = document.querySelector(replace[i]![0]) as HTMLElement | null; if (element) { - if (element instanceof HTMLScriptElement) { - element.src = ""; - } else if (element instanceof HTMLLinkElement && element.getAttribute("rel") === "stylesheet") { - element.href = ""; + const attributes = replace[i]![1]; + for (const attribute in attributes) { + element.setAttribute(attribute, attributes[attribute]); } - blocked[i] = undefined; + replace[i] = undefined; count++; - if (count >= blocked.length) { + if (count >= replace.length) { observer.disconnect(); break; } -- cgit v1.2.3