From 4993aaf41e132dd0805bf6c487901d9f2aecfcfe Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Wed, 8 Feb 2023 13:54:04 +0530 Subject: Combining similar scripts into 1 for improved performence and less files in build. --- src/manifest.json | 10 +++++----- src/scripts/auto-login.ts | 2 +- src/scripts/block-unnecessary.ts | 20 ++++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/manifest.json b/src/manifest.json index 397ec6e..8e8d0bd 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,15 +1,15 @@ { "before": { - "block-unnecessary": "*" + "block-unnecessary.ts": "*" }, "injected": { - "stop-blocking": "*" + "stop-blocking.js": "*" }, "injected_and_loaded": { - "autofill-otps": "*", - "auto-login": "*" + "autofill-otps.ts": "*", + "auto-login.ts": "*" }, "loaded": { - "autofill-captcha": "*" + "autofill-captcha.ts": "*" } } diff --git a/src/scripts/auto-login.ts b/src/scripts/auto-login.ts index 0da8ce3..1d2b379 100644 --- a/src/scripts/auto-login.ts +++ b/src/scripts/auto-login.ts @@ -1,6 +1,6 @@ const proxiedPost = $.post; -let loginData: any = null; +let loginData: any | null = null; $.post = function() { if (arguments[0].endsWith("login.action")) { diff --git a/src/scripts/block-unnecessary.ts b/src/scripts/block-unnecessary.ts index 78d294b..4163778 100644 --- a/src/scripts/block-unnecessary.ts +++ b/src/scripts/block-unnecessary.ts @@ -1,19 +1,23 @@ type ConditionalString = string | undefined; -let scriptsToBlock: ConditionalString[] = [ +let blocked: ConditionalString[] = [ "head > script:nth-child(34)", "head > script:nth-child(43)" ]; let count = 0; const observer = new MutationObserver(mutations => { - for (let i = 0; i < scriptsToBlock.length; i++) { - if (scriptsToBlock[i]) { - const script = document.querySelector(scriptsToBlock[i]!) as HTMLScriptElement; - if (script) { - script.src = ""; + for (let i = 0; i < blocked.length; i++) { + if (blocked[i]) { + const element = document.querySelector(blocked[i]!) as HTMLElement | null; + if (element) { + if (element instanceof HTMLScriptElement) { + element.src = ""; + } else if (element instanceof HTMLLinkElement && element.getAttribute("rel") === "stylesheet") { + element.href = ""; + } + blocked[i] = undefined; count++; - scriptsToBlock[i] = undefined; - if (count >= scriptsToBlock.length) { + if (count >= blocked.length) { observer.disconnect(); break; } -- cgit v1.2.3