aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-03-27 21:38:43 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-03-27 21:38:43 +0530
commitd178caee5c93ad9ed91dbd082b0f0b5a9b0507aa (patch)
treeccfdf4c6992a86955c80780de0518a2fea10ac39 /src
parent5955bd821303cffa35263c41286339fb28e7536b (diff)
downloadbanglar-bhumi-utils-d178caee5c93ad9ed91dbd082b0f0b5a9b0507aa.tar.gz
banglar-bhumi-utils-d178caee5c93ad9ed91dbd082b0f0b5a9b0507aa.zip
Refactoring code.
Only using hashes for output file names. Using singleton pattern to store the callbacks for observeDOM, and only one MutationObserver.
Diffstat (limited to 'src')
-rw-r--r--src/scripts/captcha.ts3
-rw-r--r--src/scripts/functionality/view-khatian.ts1
-rw-r--r--src/scripts/login.ts1
-rw-r--r--src/scripts/optimize.ts22
-rw-r--r--src/scripts/stop-blocking.ts2
-rw-r--r--src/shared/autofill-otp.ts2
-rw-r--r--src/shared/modify-dom.ts8
-rw-r--r--src/shared/observe-dom.ts31
-rw-r--r--src/shared/styling.ts1
9 files changed, 58 insertions, 13 deletions
diff --git a/src/scripts/captcha.ts b/src/scripts/captcha.ts
index 0eb36c9..453443c 100644
--- a/src/scripts/captcha.ts
+++ b/src/scripts/captcha.ts
@@ -1,9 +1,12 @@
const autofillCaptcha = () => {
const captchas = Array.from(document.querySelectorAll("#captchaText")) as HTMLInputElement[];
+
for (const captcha of captchas) {
const captchaParentElement = captcha.parentElement!;
+
if (captchaParentElement.id === "drawTextSpan") {
const captchaInput = captchaParentElement.parentElement!.querySelector("#drawText1") as HTMLInputElement | null;
+
if (captchaInput) {
captchaInput.value = captcha.value.replaceAll(" ", "");
captchaParentElement.parentElement!.style.display = "none";
diff --git a/src/scripts/functionality/view-khatian.ts b/src/scripts/functionality/view-khatian.ts
index 9f35762..e1d3831 100644
--- a/src/scripts/functionality/view-khatian.ts
+++ b/src/scripts/functionality/view-khatian.ts
@@ -9,6 +9,7 @@ document.addEventListener("DOMContentLoaded", () => {
arguments[2] = (data: any) => {
callback(data);
const tableElement = document.querySelector("#khdetails > table > tbody > tr > td:nth-child(1) > div:nth-child(5) > table > tbody") as HTMLElement | null;
+
if (tableElement) {
tableElement.style.height = "auto";
tableElement.style.width = "100%";
diff --git a/src/scripts/login.ts b/src/scripts/login.ts
index e2d5d5b..390131c 100644
--- a/src/scripts/login.ts
+++ b/src/scripts/login.ts
@@ -36,6 +36,7 @@ document.addEventListener("DOMContentLoaded", () => {
if (!data.exception && data.checkmsg === "success") {
loginData = arguments[1];
}
+
callback(data);
};
}
diff --git a/src/scripts/optimize.ts b/src/scripts/optimize.ts
index c8125ee..55492b6 100644
--- a/src/scripts/optimize.ts
+++ b/src/scripts/optimize.ts
@@ -1,7 +1,23 @@
import { modifyDOM } from "@/shared/modify-dom";
modifyDOM([
- ["head > script:nth-child(34)", { src: null }],
- ["head > script:nth-child(36)", { src: null, innerHTML: "$.prototype.nivoSlider = () => {};" }],
- ["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/scripts/stop-blocking.ts b/src/scripts/stop-blocking.ts
index 57357f8..f418f66 100644
--- a/src/scripts/stop-blocking.ts
+++ b/src/scripts/stop-blocking.ts
@@ -4,6 +4,7 @@ $.prototype.bind = function() {
if (arguments[0].trim() === "cut copy paste") {
arguments[1] = (e: any) => {};
}
+
return proxiedBind.apply(this, Array.from(arguments) as any);
}
@@ -11,6 +12,7 @@ const proxiedKeydown = $.prototype.keydown;
$.prototype.keydown = function() {
arguments[0] = (e: any) => true;
+
return proxiedKeydown.apply(this, Array.from(arguments) as any);
}
diff --git a/src/shared/autofill-otp.ts b/src/shared/autofill-otp.ts
index e05ea7c..b359cb4 100644
--- a/src/shared/autofill-otp.ts
+++ b/src/shared/autofill-otp.ts
@@ -26,6 +26,6 @@ document.addEventListener("DOMContentLoaded", () => {
};
});
-export const addAutofillOtps = (addedOTPAutofillList: AutofillOTPRule[]) => {
+export const addAutofillOtps = (addedOTPAutofillList: readonly AutofillOTPRule[]) => {
otpAutofillList = otpAutofillList.concat(addedOTPAutofillList);
};
diff --git a/src/shared/modify-dom.ts b/src/shared/modify-dom.ts
index b3baffb..337c879 100644
--- a/src/shared/modify-dom.ts
+++ b/src/shared/modify-dom.ts
@@ -14,12 +14,16 @@ export const modifyDOM = (modificationRules: (DOMModificaitonRule | 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 = modificationRules[i]![1] as DOMReplacements;
+ const attributes = modificationRules[i]![1];
+
if (attributes.innerHTML) {
element.innerHTML = attributes.innerHTML as string;
}
+
delete attributes.innerHTML;
+
for (const attribute in attributes) {
if (attributes[attribute] === null) {
element.removeAttribute(attribute);
@@ -27,8 +31,10 @@ export const modifyDOM = (modificationRules: (DOMModificaitonRule | null)[]) =>
element.setAttribute(attribute, attributes[attribute] as string);
}
}
+
modificationRules[i] = null;
count++;
+
if (count >= modificationRules.length) {
return true;
}
diff --git a/src/shared/observe-dom.ts b/src/shared/observe-dom.ts
index 4a447a0..dc2cb45 100644
--- a/src/shared/observe-dom.ts
+++ b/src/shared/observe-dom.ts
@@ -1,12 +1,27 @@
-export const observeDOM = (callback: () => boolean) => {
- const observer = new MutationObserver(() => {
- if (callback()) {
+type ObserveDOMCallback = () => boolean;
+
+let callbacks: (ObserveDOMCallback | null)[] = [];
+let count = 0;
+
+const observer = new MutationObserver(() => {
+ for (const callback of callbacks) {
+ if (callback && callback()) {
+ count++;
+ }
+
+ if (count >= callbacks.length) {
observer.disconnect();
+
+ break;
}
- });
+ }
+});
+
+observer.observe(document, {
+ childList: true,
+ subtree: true
+});
- observer.observe(document, {
- childList: true,
- subtree: true
- });
+export const observeDOM = (callback: ObserveDOMCallback) => {
+ callbacks.push(callback);
};
diff --git a/src/shared/styling.ts b/src/shared/styling.ts
index 0e527d9..3ec25c8 100644
--- a/src/shared/styling.ts
+++ b/src/shared/styling.ts
@@ -1,5 +1,6 @@
export const styles = (selector: string, styles: { [key: string]: string }) => {
const elements = Array.from(document.querySelectorAll(selector)) as HTMLElement[];
+
for (const element of elements) {
for (const styleType in styles) {
element.style[styleType as any] = styles[styleType];