diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-08 13:54:04 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-08 13:54:04 +0530 |
| commit | 4993aaf41e132dd0805bf6c487901d9f2aecfcfe (patch) | |
| tree | a51ebf7bff551e9188d68f777d100e8ffb70922d /src | |
| parent | 8234acb45cd99fc7bcd99df7f71cac02845bb534 (diff) | |
| download | banglar-bhumi-utils-4993aaf41e132dd0805bf6c487901d9f2aecfcfe.tar.gz banglar-bhumi-utils-4993aaf41e132dd0805bf6c487901d9f2aecfcfe.zip | |
Combining similar scripts into 1 for improved performence and less files in build.
Diffstat (limited to 'src')
| -rw-r--r-- | src/manifest.json | 10 | ||||
| -rw-r--r-- | src/scripts/auto-login.ts | 2 | ||||
| -rw-r--r-- | src/scripts/block-unnecessary.ts | 20 |
3 files changed, 18 insertions, 14 deletions
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; } |
