From a9f2d88e1e5b1c7ddf524db8b5b185b8485f8d48 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Fri, 24 Mar 2023 09:24:15 +0530 Subject: Improved some functionality. --- .../create-manifest-webpack-plugin/index.js | 2 +- .../get-injection-code.js | 19 ++++++- .../plugins/inject-script-webpack-plugin/index.js | 2 +- src/scripts.json | 12 ++--- src/scripts/auto-login.ts | 34 ------------ src/scripts/autofill-captcha.ts | 28 ---------- src/scripts/autofill-otps/grievance-application.ts | 22 -------- src/scripts/captcha.ts | 17 ++++++ src/scripts/fix-application-receipt.ts | 21 -------- src/scripts/functionality/application-receipt.ts | 21 ++++++++ src/scripts/functionality/view-khatian.ts | 21 ++++++++ src/scripts/login.ts | 60 ++++++++++++++++++++++ src/scripts/optimize/home-page/index.ts | 9 ---- src/scripts/optimize/home-page/modify-dom.ts | 9 ++++ src/scripts/optimize/home-page/styles.ts | 12 +---- src/scripts/otps/grievance-application.ts | 22 ++++++++ src/scripts/show-plot-information.ts | 11 ---- 17 files changed, 177 insertions(+), 145 deletions(-) delete mode 100644 src/scripts/auto-login.ts delete mode 100644 src/scripts/autofill-captcha.ts delete mode 100644 src/scripts/autofill-otps/grievance-application.ts create mode 100644 src/scripts/captcha.ts delete mode 100644 src/scripts/fix-application-receipt.ts create mode 100644 src/scripts/functionality/application-receipt.ts create mode 100644 src/scripts/functionality/view-khatian.ts create mode 100644 src/scripts/login.ts delete mode 100644 src/scripts/optimize/home-page/index.ts create mode 100644 src/scripts/optimize/home-page/modify-dom.ts create mode 100644 src/scripts/otps/grievance-application.ts delete mode 100644 src/scripts/show-plot-information.ts diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js index f571986..f0d9084 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -18,7 +18,7 @@ class CreateManifestPlugin { const scripts = formatScripts(require(path.resolve(SOURCE_DIR, "scripts.json"))); const manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json"); manifest.version = require(path.resolve(ROOT_DIR, "package.json")).version; - manifest.content_scripts = [] + manifest.content_scripts = []; for (const scriptPath in scripts) { for (const scriptType in scripts[scriptPath]) { diff --git a/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js b/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js index 6f3c9b3..2993c44 100644 --- a/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js +++ b/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js @@ -1 +1,18 @@ -module.exports = code => `(()=>{const o=new MutationObserver(()=>{let t=document.querySelector("head > script:nth-child(54)");if(t){let e=\`(()=>{${code.replaceAll("`","\\`")}})();\`;null==t.getAttribute("data-replaced")?(t.innerHTML=e,t.setAttribute("data-replaced","")):t.innerHTML+=e,o.disconnect()}});o.observe(document,{childList:!0,subtree:!0});})();`; +module.exports.getInjectionCode = code => { + const escapeSequences = [["\b", "\\b"], + ["\f", "\\f"], + ["\n", "\\n"], + ["\r", "\\r"], + ["\t", "\\t"], + ["\v", "\\v"] + ]; + let finalCode = code.replaceAll("`","\\`"); + + for (const escapeSequence of escapeSequences) { + finalCode = finalCode + .replaceAll(escapeSequence[1], "\\" + escapeSequence[1]) + .replaceAll(escapeSequence[0], escapeSequence[1]); + } + + return `(()=>{const o=new MutationObserver(()=>{let t=document.querySelector("head > script:nth-child(54)");if(t){let e=\`(()=>{${finalCode}})();\`;null==t.getAttribute("data-replaced")?(t.innerHTML=e,t.setAttribute("data-replaced","")):t.innerHTML+=e,o.disconnect()}});o.observe(document,{childList:!0,subtree:!0});})();`; +}; diff --git a/config/webpack/plugins/inject-script-webpack-plugin/index.js b/config/webpack/plugins/inject-script-webpack-plugin/index.js index b7b5940..a0ee1f7 100644 --- a/config/webpack/plugins/inject-script-webpack-plugin/index.js +++ b/config/webpack/plugins/inject-script-webpack-plugin/index.js @@ -1,7 +1,7 @@ const { sources } = require("webpack"); const terser = require("terser"); -const getInjectionCode = webpackRequire("plugins/inject-script-webpack-plugin/get-injection-code"); +const { getInjectionCode } = webpackRequire("plugins/inject-script-webpack-plugin/get-injection-code"); class InjectScriptPlugin { apply(compiler) { diff --git a/src/scripts.json b/src/scripts.json index f5611fe..c6caca8 100644 --- a/src/scripts.json +++ b/src/scripts.json @@ -1,17 +1,17 @@ { "before": { "optimize/index.ts": "*", - "optimize/home-page/index.ts": "Home" + "optimize/home-page/modify-dom.ts": "Home" }, "injected": { "stop-blocking.js": "*", - "auto-login.ts": "*", - "autofill-otps/grievance-application.ts": "GrievAppViewAction.action", - "show-plot-information.ts": "KnowYourProperty.action" + "login.ts": "*", + "otps/grievance-application.ts": "GrievAppViewAction.action", + "functionality/view-khatian.ts": "KnowYourProperty.action" }, "loaded": { - "autofill-captcha.ts": "*", + "captcha.ts": "*", "optimize/home-page/styles.ts": "Home", - "fix-application-receipt.ts": "Apprecrep.action" + "functionality/application-receipt.ts": "Apprecrep.action" } } diff --git a/src/scripts/auto-login.ts b/src/scripts/auto-login.ts deleted file mode 100644 index ae1682b..0000000 --- a/src/scripts/auto-login.ts +++ /dev/null @@ -1,34 +0,0 @@ -document.addEventListener("DOMContentLoaded", () => { - const proxiedPost = $.post; - - 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); - }; - } - - 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); -}); diff --git a/src/scripts/autofill-captcha.ts b/src/scripts/autofill-captcha.ts deleted file mode 100644 index f290fda..0000000 --- a/src/scripts/autofill-captcha.ts +++ /dev/null @@ -1,28 +0,0 @@ -const autofillCaptcha = () => { - let captchas = Array.from(document.querySelectorAll("#txtCaptcha")) as HTMLInputElement[]; - - for (const captcha of captchas) { - const captchaInput = captcha.parentElement!.querySelector("#txtInput") as HTMLInputElement | null; - if (captchaInput) { - captchaInput.value = captcha.value.replaceAll(" ", ""); - captchaInput.style.display = "none"; - captcha.style.display = "none"; - } - } - - 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"; - } - } - } - - setTimeout(autofillCaptcha, 1000); -}; - -autofillCaptcha(); diff --git a/src/scripts/autofill-otps/grievance-application.ts b/src/scripts/autofill-otps/grievance-application.ts deleted file mode 100644 index 140504c..0000000 --- a/src/scripts/autofill-otps/grievance-application.ts +++ /dev/null @@ -1,22 +0,0 @@ -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; - } - - 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); - }; -}); diff --git a/src/scripts/captcha.ts b/src/scripts/captcha.ts new file mode 100644 index 0000000..0eb36c9 --- /dev/null +++ b/src/scripts/captcha.ts @@ -0,0 +1,17 @@ +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"; + } + } + } + + setTimeout(autofillCaptcha, 1000); +}; + +autofillCaptcha(); diff --git a/src/scripts/fix-application-receipt.ts b/src/scripts/fix-application-receipt.ts deleted file mode 100644 index 11dddf0..0000000 --- a/src/scripts/fix-application-receipt.ts +++ /dev/null @@ -1,21 +0,0 @@ -const receiptFormElement = document.querySelector("#form_reprint_request")!; -receiptFormElement.removeAttribute("id"); -receiptFormElement.removeAttribute("name"); -receiptFormElement.removeAttribute("onsubmit"); -receiptFormElement.removeAttribute("target"); -receiptFormElement.removeAttribute("autocomplete"); -receiptFormElement.removeAttribute("rel"); - -let captchaElement = document.querySelector("#werter > div > div:nth-child(4)"); - -if (captchaElement) { - captchaElement = captchaElement!; - const captchaValueElement = document.querySelector("#captchaText") as HTMLInputElement; - const captchaFieldElement = document.querySelector("[name=txtDrawText]") as HTMLInputElement; - const removeCaptcha = () => { - captchaFieldElement.value = captchaValueElement.value; - (captchaElement as any).style.display = "none"; - setTimeout(removeCaptcha, 1000); - }; - removeCaptcha(); -} diff --git a/src/scripts/functionality/application-receipt.ts b/src/scripts/functionality/application-receipt.ts new file mode 100644 index 0000000..7fdf4d0 --- /dev/null +++ b/src/scripts/functionality/application-receipt.ts @@ -0,0 +1,21 @@ +const receiptFormElement = document.querySelector("#form_reprint_request") as HTMLElement; +receiptFormElement.removeAttribute("id"); +receiptFormElement.removeAttribute("name"); +receiptFormElement.removeAttribute("onsubmit"); +receiptFormElement.removeAttribute("target"); +receiptFormElement.removeAttribute("autocomplete"); +receiptFormElement.removeAttribute("rel"); + +let captchaElement = document.querySelector("#werter > div > div:nth-child(4)") as HTMLElement; + +if (captchaElement) { + captchaElement = captchaElement!; + const captchaValueElement = document.querySelector("#captchaText") as HTMLInputElement; + const captchaFieldElement = document.querySelector("[name=txtDrawText]") as HTMLInputElement; + const removeCaptcha = () => { + captchaFieldElement.value = captchaValueElement.value; + captchaElement.style.display = "none"; + setTimeout(removeCaptcha, 1000); + }; + removeCaptcha(); +} diff --git a/src/scripts/functionality/view-khatian.ts b/src/scripts/functionality/view-khatian.ts new file mode 100644 index 0000000..9f35762 --- /dev/null +++ b/src/scripts/functionality/view-khatian.ts @@ -0,0 +1,21 @@ +declare function loadKhatian(): void; + +document.addEventListener("DOMContentLoaded", () => { + const proxiedPost = $.post; + + $.post = function() { + if (arguments[0].startsWith("khDetailsAction_LandInfo.action")) { + const callback = arguments[2]; + 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%"; + } + } + } + + return proxiedPost.apply(this, Array.from(arguments) as any); + } +}); diff --git a/src/scripts/login.ts b/src/scripts/login.ts new file mode 100644 index 0000000..e2d5d5b --- /dev/null +++ b/src/scripts/login.ts @@ -0,0 +1,60 @@ +document.addEventListener("DOMContentLoaded", () => { + const proxiedPost = $.post; + + let loginData: any | null = null; + + $.post = function() { + if (arguments[0].endsWith("viewLoginAreaAction")) { + (window as any).DrawLoginCaptcha = () => {}; + const callback = arguments[1]; + arguments[1] = (html: any) => { + callback(html); + const captchaValueElement = document.getElementById("txtCaptcha") as HTMLInputElement; + const captchaInputElement = document.getElementById("txtInput") as HTMLInputElement; + captchaValueElement.value = "ffffff"; + captchaInputElement.value = "ffffff"; + captchaValueElement.style.display = "none"; + captchaInputElement.style.display = "none"; + (document.querySelector(".captcharefresh") as HTMLElement).style.display = "none"; + } + } else if (arguments[0].endsWith("viewPasswordRecoveryArea")) { + (window as any).Captcha = () => {}; + const callback = arguments[1]; + arguments[1] = (html: any) => { + callback(html); + const captchaInputElement = document.getElementById("dText") as HTMLInputElement; + const captchaValueElement = document.getElementById("captaText") as HTMLInputElement; + captchaValueElement.value = "ffffff"; + captchaInputElement.value = "ffffff"; + captchaValueElement.style.display = "none"; + captchaInputElement.style.display = "none"; + (document.getElementById("captchaRef") as HTMLElement).style.display = "none"; + } + } else 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); + }; + + 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/optimize/home-page/index.ts b/src/scripts/optimize/home-page/index.ts deleted file mode 100644 index 762b4f8..0000000 --- a/src/scripts/optimize/home-page/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { modifyDOM, DOMModifier } from "@/utils/modify-dom"; - -const bannerImageUrl = chrome.runtime.getURL("assets/banner.jpg"); - -modifyDOM([ - new DOMModifier("#slider > img", { - src: bannerImageUrl - }) -]); diff --git a/src/scripts/optimize/home-page/modify-dom.ts b/src/scripts/optimize/home-page/modify-dom.ts new file mode 100644 index 0000000..762b4f8 --- /dev/null +++ b/src/scripts/optimize/home-page/modify-dom.ts @@ -0,0 +1,9 @@ +import { modifyDOM, DOMModifier } from "@/utils/modify-dom"; + +const bannerImageUrl = chrome.runtime.getURL("assets/banner.jpg"); + +modifyDOM([ + new DOMModifier("#slider > img", { + src: bannerImageUrl + }) +]); diff --git a/src/scripts/optimize/home-page/styles.ts b/src/scripts/optimize/home-page/styles.ts index 91d273a..249b361 100644 --- a/src/scripts/optimize/home-page/styles.ts +++ b/src/scripts/optimize/home-page/styles.ts @@ -1,20 +1,10 @@ import { styles } from "@/utils/styling"; -styles("#form_MainMenuPage > div > div.logo-div.row.ng-scope > div.top_link_icon.col-sm-7.float-right", { - width: "100%", - display: "flex", - justifyContent: "space-around", - paddingTop: "5px" -}); -styles("#form_MainMenuPage > div > div.logo-div.row.ng-scope > div.top_link_icon.col-sm-7.float-right > a > span > i", { - height: "40px", - width: "40px", - paddingTop: "10px" -}); styles("#slider", { overflow: "visible", position: "initial" }); + styles("#slider > img", { width: "100vw", position: "initial" diff --git a/src/scripts/otps/grievance-application.ts b/src/scripts/otps/grievance-application.ts new file mode 100644 index 0000000..140504c --- /dev/null +++ b/src/scripts/otps/grievance-application.ts @@ -0,0 +1,22 @@ +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; + } + + 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); + }; +}); diff --git a/src/scripts/show-plot-information.ts b/src/scripts/show-plot-information.ts deleted file mode 100644 index aec56d6..0000000 --- a/src/scripts/show-plot-information.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare function loadKhatian(): void; - -document.addEventListener("DOMContentLoaded", () => { - (window as any).customLoadKhatian = () => { - loadKhatian(); - setTimeout(() => { - (document.querySelector("#khdetails > table > tbody > tr > td:nth-child(1) > div:nth-child(5) > table > tbody") as any).style.height = "auto"; - }, 1000); - }; - document.querySelector("#khbutton")!.setAttribute("onclick", "customLoadKhatian()"); -}); -- cgit v1.2.3