aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/functionality
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2024-03-12 14:22:41 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2024-03-12 14:22:41 +0530
commit95becf369822cbb74f4cefb5658f3ff97e164d6e (patch)
treee00c49ed93744d4e97d9c9460baf2dc5fec84e86 /src/scripts/functionality
parenta90f2e98c72ae2e04ba8b65e9a316eb08b5d6bea (diff)
downloadbanglar-bhumi-utils-95becf369822cbb74f4cefb5658f3ff97e164d6e.tar.gz
banglar-bhumi-utils-95becf369822cbb74f4cefb5658f3ff97e164d6e.zip
Using jquery for injected codes to maintain consistency.
Diffstat (limited to 'src/scripts/functionality')
-rw-r--r--src/scripts/functionality/application-receipt.ts35
-rw-r--r--src/scripts/functionality/mutation-application.ts10
-rw-r--r--src/scripts/functionality/view-khatian/download-information-pdf-page-content.html15
-rw-r--r--src/scripts/functionality/view-khatian/index.ts85
4 files changed, 73 insertions, 72 deletions
diff --git a/src/scripts/functionality/application-receipt.ts b/src/scripts/functionality/application-receipt.ts
index 878b910..704d865 100644
--- a/src/scripts/functionality/application-receipt.ts
+++ b/src/scripts/functionality/application-receipt.ts
@@ -1,21 +1,20 @@
-const receiptFormElement = document.getElementById("form_reprint_request") as HTMLElement;
-receiptFormElement.removeAttribute("id");
-receiptFormElement.removeAttribute("name");
-receiptFormElement.removeAttribute("onsubmit");
-receiptFormElement.removeAttribute("target");
-receiptFormElement.removeAttribute("autocomplete");
-receiptFormElement.removeAttribute("rel");
+$("#form_reprint_request")
+ .removeAttr("id")
+ .removeAttr("name")
+ .removeAttr("onsubmit")
+ .removeAttr("target")
+ .removeAttr("autocomplete")
+ .removeAttr("rel");
-let captchaElement = document.querySelector("#werter > div > div:nth-child(4)") as HTMLElement;
+const captchaElement = $("#werter > div > div:nth-child(4)");
-if (captchaElement) {
- captchaElement = captchaElement!;
- const captchaValueElement = document.getElementById("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();
+if (captchaElement.length > 0) {
+ const captchaValueElement = $("#captchaText");
+ const captchaFieldElement = $("[name=txtDrawText]");
+
+ setInterval(() => {
+ captchaFieldElement.val("FFFFFF");
+ captchaValueElement.val("FFFFFF");
+ captchaElement.hide();
+ }, 1000);
}
diff --git a/src/scripts/functionality/mutation-application.ts b/src/scripts/functionality/mutation-application.ts
index afc133f..c212823 100644
--- a/src/scripts/functionality/mutation-application.ts
+++ b/src/scripts/functionality/mutation-application.ts
@@ -5,11 +5,11 @@ const sanghaFacilitationCentreBannerUrl = chrome.runtime.getURL("/assets/sangha-
document.addEventListener("DOMContentLoaded", () => {
observeDOM(() => {
- const formElement = document.querySelector("#form_MutationApplication > div > div:nth-child(14) > div.col-sm-2.btreset > form");
- const submitButtonElement = document.getElementById("btnDeclareForm");
- if (formElement && submitButtonElement) {
- formElement.removeAttribute("action");
- submitButtonElement.addEventListener("click", e => {
+ const formElement = $("#form_MutationApplication > div > div:nth-child(14) > div.col-sm-2.btreset > form");
+ const submitButtonElement = $("#btnDeclareForm");
+ if (formElement.length > 0 && submitButtonElement.length > 0) {
+ formElement.removeAttr("action");
+ submitButtonElement.click(e => {
e.preventDefault();
(async () => {
diff --git a/src/scripts/functionality/view-khatian/download-information-pdf-page-content.html b/src/scripts/functionality/view-khatian/download-information-pdf-page-content.html
index e91c15e..44ced4f 100644
--- a/src/scripts/functionality/view-khatian/download-information-pdf-page-content.html
+++ b/src/scripts/functionality/view-khatian/download-information-pdf-page-content.html
@@ -1,4 +1,10 @@
<div id="content">
+ <style type="text/css" media="print">
+ @page {
+ size: A4;
+ margin: 0;
+ }
+ </style>
<style>
* {
box-sizing: border-box !important;
@@ -184,11 +190,6 @@
width: 50%;
}
- @page {
- size: A4;
- margin: 0 0 5rem 0;
- }
-
footer {
heigth: 5rem;
width: 100%;
@@ -202,10 +203,6 @@
bottom: 0;
}
- @page {
- size: A4;
- }
-
body {
width: 210mm !important;
height: 297mm !important;
diff --git a/src/scripts/functionality/view-khatian/index.ts b/src/scripts/functionality/view-khatian/index.ts
index 38e500b..1ca37c5 100644
--- a/src/scripts/functionality/view-khatian/index.ts
+++ b/src/scripts/functionality/view-khatian/index.ts
@@ -1,4 +1,5 @@
import { generateWebPage } from "@/shared/generate-web-page";
+import { interceptPost } from "@/shared/intercept-jquery-ajax";
import getDownloadInformationPDFPageContent from "@/scripts/functionality/view-khatian/download-information-pdf-page-content.html";
declare function load(): void;
@@ -6,14 +7,12 @@ declare function load(): void;
const sanghaFacilitationCentreBannerUrl = chrome.runtime.getURL("/assets/sangha-facilitation-centre-banner.jpg");
document.addEventListener("DOMContentLoaded", () => {
- const proxiedPost = $.post;
+ const submitButtonElement = $("#khbutton");
+ const separatorElement = $("#bodycover > div > form > hr:nth-child(2)");
+ const formElement = $("#bodycover > div > form");
+ let downloadPDFButton: JQuery<HTMLButtonElement> | null = null;
- const submitButtonElement = document.querySelector("#khbutton") as HTMLButtonElement;
- const separatorElement = document.querySelector("#bodycover > div > form > hr:nth-child(2)") as HTMLElement;
- const formElement = document.querySelector("#bodycover > div > form") as HTMLElement;
- let downloadPDFButton: HTMLButtonElement | null = null;
-
- const submitButtonElementComputedStyles = window.getComputedStyle(submitButtonElement);
+ const submitButtonElementComputedStyles = window.getComputedStyle(submitButtonElement[0]);
const styles = Array.from(submitButtonElementComputedStyles)
.reduce(
(str, property) => `${str}${property}:${submitButtonElementComputedStyles.getPropertyValue(property)};`,
@@ -21,60 +20,66 @@ document.addEventListener("DOMContentLoaded", () => {
);
const getValueOfSelectElement = (selector: string) => {
- const element = document.querySelector(selector) as HTMLSelectElement;
+ const element = document.querySelector<HTMLSelectElement>(selector)!;
return element.options[element.selectedIndex].text;
};
let isPlotInformation: boolean | null = null;
const downloadInformationPDF = () => {
- generateWebPage(getDownloadInformationPDFPageContent({
- sanghaFacilitationCentreBannerUrl,
- isPlotInformation: !!isPlotInformation,
- details: document.getElementById(isPlotInformation ? "plotdetails" : "khdetails")!.innerHTML,
- district: getValueOfSelectElement("#lstDistrictCode1"),
- block: getValueOfSelectElement("#lstBlockCode1"),
- mouza: getValueOfSelectElement("#lstMouzaList")
- }));
+ generateWebPage(
+ getDownloadInformationPDFPageContent({
+ sanghaFacilitationCentreBannerUrl,
+ isPlotInformation: !!isPlotInformation,
+ details: $(isPlotInformation ? "#plotdetails" : "#khdetails").html(),
+ district: getValueOfSelectElement("#lstDistrictCode1"),
+ block: getValueOfSelectElement("#lstBlockCode1"),
+ mouza: getValueOfSelectElement("#lstMouzaList")
+ }),
+ isPlotInformation
+ ? "Plot Details"
+ : "Khatian Details"
+ );
};
- $.post = function() {
- if (arguments[0].startsWith("plotDetailsAction_LandInfo.action")) {
- isPlotInformation = true;
- } else if (arguments[0].startsWith("khDetailsAction_LandInfo.action")) {
- isPlotInformation = false;
- }
-
+ const showDownloadButton = (args: any) => {
if (isPlotInformation !== null) {
- const callback = arguments[2];
- arguments[2] = (data: any) => {
+ const callback = args[2];
+ args[2] = (data: any) => {
callback(data);
- const tableElement = document.querySelector(isPlotInformation
+ const tableElement = $(isPlotInformation
? "#plotdetails > div:nth-child(1) > div:nth-child(4) > table > tbody"
: "#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%";
+ if (tableElement.length > 0) {
+ tableElement.css("height", "auto");
+ tableElement.css("width", "100%");
if (!downloadPDFButton) {
- downloadPDFButton = document.createElement("button");
- downloadPDFButton.innerHTML = "Download PDF";
- downloadPDFButton.style.cssText = styles;
- downloadPDFButton.style.width = "auto";
- downloadPDFButton.style.marginBottom = "1rem";
- downloadPDFButton.addEventListener("click", downloadInformationPDF);
- formElement.insertBefore(downloadPDFButton, separatorElement);
+ downloadPDFButton = $(document.createElement("button"));
+ downloadPDFButton.html("Download PDF");
+ downloadPDFButton[0].style.cssText = styles;
+ downloadPDFButton.css("width", "auto");
+ downloadPDFButton.css("margin-bottom", "1rem");
+ downloadPDFButton.click(downloadInformationPDF);
+ formElement[0].insertBefore(downloadPDFButton[0], separatorElement[0]);
}
} else if (downloadPDFButton) {
- formElement.removeChild(downloadPDFButton);
+ $(downloadPDFButton).remove();
isPlotInformation = null;
downloadPDFButton = null;
}
}
}
+ };
- return proxiedPost.apply(this, Array.from(arguments) as any);
- }
+ interceptPost("plotDetailsAction_LandInfo.action", args => {
+ isPlotInformation = true;
+ showDownloadButton(args);
+ });
+ interceptPost("plotDetailsAction_LandInfo.action", args => {
+ isPlotInformation = false;
+ showDownloadButton(args);
+ });
});