diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-13 22:49:42 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-13 22:49:42 +0530 |
| commit | 34ad953c953a395ba3e51c8125034a6bb65b2a79 (patch) | |
| tree | 253cc30047bb3963f387bd340d50938b3b727053 /src/scripts | |
| parent | aeeabaa0050ecb9e43b1a3fb309f314d92d3ca97 (diff) | |
| download | banglar-bhumi-utils-34ad953c953a395ba3e51c8125034a6bb65b2a79.tar.gz banglar-bhumi-utils-34ad953c953a395ba3e51c8125034a6bb65b2a79.zip | |
Fixed not being able to import modules in scripts.
Diffstat (limited to 'src/scripts')
| -rw-r--r-- | src/scripts/auto-login.ts | 58 | ||||
| -rw-r--r-- | src/scripts/autofill-otps.ts | 36 | ||||
| -rw-r--r-- | src/scripts/optimize/home-page.ts | 10 | ||||
| -rw-r--r-- | src/scripts/optimize/index.ts | 10 |
4 files changed, 61 insertions, 53 deletions
diff --git a/src/scripts/auto-login.ts b/src/scripts/auto-login.ts index 1d2b379..ae1682b 100644 --- a/src/scripts/auto-login.ts +++ b/src/scripts/auto-login.ts @@ -1,32 +1,34 @@ -const proxiedPost = $.post; +document.addEventListener("DOMContentLoaded", () => { + const proxiedPost = $.post; -let loginData: any | null = null; + let loginData: any | null = null; -$.post = function() { - if (arguments[0].endsWith("login.action")) { - const callback = arguments[2]; - arguments[2] = (data: any) => { - if (!data.exception && data.checkmsg === "success") { - loginData = arguments[1]; - } - callback(data); - }; - } + $.post = function() { + if (arguments[0].endsWith("login.action")) { + const callback = arguments[2]; + arguments[2] = (data: any) => { + if (!data.exception && data.checkmsg === "success") { + loginData = arguments[1]; + } + callback(data); + }; + } - return proxiedPost.apply(this, Array.from(arguments) as any); -}; + return proxiedPost.apply(this, Array.from(arguments) as any); + }; -setInterval(() => { - if (loginData) { - $.post( - "/BanglarBhumi/login.action", - loginData, - data => { - if (data.exception || data.checkmsg !== "success") { - loginData = null; - } - }, - "json" - ); - } -}, 1000 * 60 * 5); + setInterval(() => { + if (loginData) { + $.post( + "/BanglarBhumi/login.action", + loginData, + data => { + if (data.exception || data.checkmsg !== "success") { + loginData = null; + } + }, + "json" + ); + } + }, 1000 * 60 * 5); +}); diff --git a/src/scripts/autofill-otps.ts b/src/scripts/autofill-otps.ts index f2c5650..140504c 100644 --- a/src/scripts/autofill-otps.ts +++ b/src/scripts/autofill-otps.ts @@ -1,20 +1,22 @@ -const proxiedPost = $.post; +document.addEventListener("DOMContentLoaded", () => { + const proxiedPost = $.post; -$.post = function() { - let element: HTMLInputElement | null = null; - if (arguments[0].endsWith("MISPetitionSmsSend.action")) { - element = document.querySelector("input[name=mobile_Code]") as HTMLInputElement; - } else if (arguments[0].endsWith("MISPetitionEmailSend.action")) { - element = document.querySelector("input[name=txtemail_Code]") as HTMLInputElement; - } + $.post = function() { + let element: HTMLInputElement | null = null; + if (arguments[0].endsWith("MISPetitionSmsSend.action")) { + element = document.querySelector("input[name=mobile_Code]") as HTMLInputElement; + } else if (arguments[0].endsWith("MISPetitionEmailSend.action")) { + element = document.querySelector("input[name=txtemail_Code]") as HTMLInputElement; + } - if (element) { - const callback = arguments[2]; - arguments[2] = (data: any) => { - element!.value = data?.messageShow || ""; - callback(data); - }; - } + if (element) { + const callback = arguments[2]; + arguments[2] = (data: any) => { + element!.value = data?.messageShow || ""; + callback(data); + }; + } - return proxiedPost.apply(this, Array.from(arguments) as any); -}; + return proxiedPost.apply(this, Array.from(arguments) as any); + }; +}); diff --git a/src/scripts/optimize/home-page.ts b/src/scripts/optimize/home-page.ts index 5ca4c2e..2affea7 100644 --- a/src/scripts/optimize/home-page.ts +++ b/src/scripts/optimize/home-page.ts @@ -1,10 +1,12 @@ +import observeDOM from "@/utils/observe-dom"; + const replace: (any[] | undefined)[] = [ ["#slider > img", { src: "" }], ["#slider > img.nivo-main-image", { src: "" }] ]; let count = 0; -const observer = new MutationObserver(() => { +observeDOM(() => { for (let i = 0; i < replace.length; i++) { if (replace[i]) { const element = document.querySelector(replace[i]![0]) as HTMLElement | null; @@ -20,11 +22,11 @@ const observer = new MutationObserver(() => { replace[i] = undefined; count++; if (count >= replace.length) { - observer.disconnect(); - break; + return true; } } } } + + return false; }); -observer.observe(document, {childList: true, subtree: true}); diff --git a/src/scripts/optimize/index.ts b/src/scripts/optimize/index.ts index 8b63c53..37ae12e 100644 --- a/src/scripts/optimize/index.ts +++ b/src/scripts/optimize/index.ts @@ -1,10 +1,12 @@ +import observeDOM from "@/utils/observe-dom"; + const replace: (any[] | undefined)[] = [ ["head > script:nth-child(34)", { src: "" }], ["head > script:nth-child(43)", { src: "" }] ]; let count = 0; -const observer = new MutationObserver(() => { +observeDOM(() => { for (let i = 0; i < replace.length; i++) { if (replace[i]) { const element = document.querySelector(replace[i]![0]) as HTMLElement | null; @@ -20,11 +22,11 @@ const observer = new MutationObserver(() => { replace[i] = undefined; count++; if (count >= replace.length) { - observer.disconnect(); - break; + return true; } } } } + + return false; }); -observer.observe(document, {childList: true, subtree: true}); |
