aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 23:17:25 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 23:17:25 +0530
commit68777ec421d41be0da27013afd4165ae7d658d26 (patch)
tree4c1cc6af7acfeac54b2e54372944344d3f5b9a26 /src/scripts
parent20c3b38f24d79df8843f17985a7d13533d4e0d10 (diff)
downloadbanglar-bhumi-utils-68777ec421d41be0da27013afd4165ae7d658d26.tar.gz
banglar-bhumi-utils-68777ec421d41be0da27013afd4165ae7d658d26.zip
refactor: added linting with esling and also resolved warnings for it
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/common/login/captcha.ts46
-rw-r--r--src/scripts/common/login/index.ts2
-rw-r--r--src/scripts/common/stop-blocking.ts4
-rw-r--r--src/scripts/pages/application-receipt/captcha.ts6
-rw-r--r--src/scripts/pages/know-your-property/captcha.ts6
-rw-r--r--src/scripts/pages/mutation-application/download-button.ts15
-rw-r--r--src/scripts/pages/sheet-map/index.ts90
-rw-r--r--src/scripts/pages/view-khatian/index.ts28
8 files changed, 113 insertions, 84 deletions
diff --git a/src/scripts/common/login/captcha.ts b/src/scripts/common/login/captcha.ts
index 73e8995..a63aa24 100644
--- a/src/scripts/common/login/captcha.ts
+++ b/src/scripts/common/login/captcha.ts
@@ -1,4 +1,5 @@
import { observeDOM } from "@/shared/observe-dom";
+import { OCRRequest, OCRResponse } from "@/shared/ocr-request";
/**
* Pre-processes a CAPTCHA image on a canvas by removing grayish
@@ -9,18 +10,18 @@ import { observeDOM } from "@/shared/observe-dom";
* @param width - Canvas width in pixels.
* @param height - Canvas height in pixels.
*/
-export function prepareCaptcha(ctx: CanvasRenderingContext2D, width: number, height: number) {
+export function prepareCaptcha(ctx: CanvasRenderingContext2D, width: number, height: number): void {
const imgData = ctx.getImageData(0, 0, width, height);
const data = imgData.data;
const radius = 1;
/** Returns true when all three channels are below 50 (very dark). */
- function isBlack(r: number, g: number, b: number) {
+ function isBlack(r: number, g: number, b: number): boolean {
return r < 50 && g < 50 && b < 50;
}
/** Returns true when the colour is a mid-range grey (no strong hue). */
- function isGrayish(r: number, g: number, b: number) {
+ function isGrayish(r: number, g: number, b: number): boolean {
return Math.abs(r - g) < 15 && Math.abs(g - b) < 15 && r > 100 && r < 200;
}
@@ -28,7 +29,7 @@ export function prepareCaptcha(ctx: CanvasRenderingContext2D, width: number, hei
* Checks whether a black pixel exists within `radius` pixels of (x, y).
* Used to preserve dark structures when removing grey noise.
*/
- function hasNearbyBlack(x: number, y: number) {
+ function hasNearbyBlack(x: number, y: number): boolean {
for (let dx = -radius; dx <= radius; dx++) {
for (let dy = -radius; dy <= radius; dy++) {
const nx = x + dx;
@@ -65,14 +66,17 @@ export function prepareCaptcha(ctx: CanvasRenderingContext2D, width: number, hei
}
observeDOM(() => {
- const loginFormElement = document.querySelector("#loginform") as (HTMLFormElement | undefined);
+ const loginFormElement = document.querySelector<HTMLFormElement>("#loginform");
if (loginFormElement) {
- const captchaImg = loginFormElement.querySelector("#captchaImg") as HTMLImageElement;
- const captchaInput = loginFormElement.querySelector("#txtInput") as HTMLInputElement;
+ const captchaImg = loginFormElement.querySelector<HTMLImageElement>("#captchaImg");
+ const captchaInput = loginFormElement.querySelector<HTMLInputElement>("#txtInput");
+
+ if (!captchaImg || !captchaInput)
+ return false;
// Wait for image to load to get correct dimensions
- captchaImg.addEventListener("load", async () => {
+ captchaImg.addEventListener("load", function(): void {
const { width, height } = captchaImg;
// 1. Create canvas
@@ -86,33 +90,35 @@ observeDOM(() => {
canvas.style.display = "none";
// 3. Insert canvas before image
- captchaImg.parentNode!.querySelectorAll("canvas").forEach(c => c.remove());
- captchaImg.parentNode!.insertBefore(canvas, captchaImg);
+ captchaImg.parentNode?.querySelectorAll("canvas")
+ .forEach((c) => { c.remove(); });
+ captchaImg.parentNode?.insertBefore(canvas, captchaImg);
// 4. Hide image
captchaImg.style.display = "none";
// 5. Draw the image onto the canvas
- const ctx = canvas.getContext("2d")!;
+ const ctx = canvas.getContext("2d");
+ if (!ctx)
+ return;
ctx.drawImage(captchaImg, 0, 0);
prepareCaptcha(ctx, canvas.width, canvas.height);
canvas.style.display = "";
const dataURL = canvas.toDataURL("image/png");
// Perform OCR
- chrome.runtime.sendMessage(
+ chrome.runtime.sendMessage<OCRRequest, OCRResponse>(
{ type: "OCR", dataURL },
- ({ success, text, confidence }) => {
- if (success) {
- const textResult = text.trim();
- if (confidence < 80 || textResult.length !== 6) {
+ function(ocrResponse): void {
+ if (ocrResponse.success) {
+ const textResult = ocrResponse.text.trim();
+ if (ocrResponse.confidence < 80 || textResult.length !== 6)
// Reset the captcha if confidence is low
- captchaImg.src = "generateCaptcha?" + new Date().getTime();
- } else {
+ captchaImg.src = `generateCaptcha?${new Date().getTime().toString()}`;
+ else
captchaInput.value = textResult;
- }
}
- },
+ }
);
});
}
diff --git a/src/scripts/common/login/index.ts b/src/scripts/common/login/index.ts
index 17e2117..95b9c5b 100644
--- a/src/scripts/common/login/index.ts
+++ b/src/scripts/common/login/index.ts
@@ -1 +1 @@
-import "@/scripts/login/captcha";
+import "@/scripts/common/login/captcha";
diff --git a/src/scripts/common/stop-blocking.ts b/src/scripts/common/stop-blocking.ts
index 3fa3de6..bdebfe9 100644
--- a/src/scripts/common/stop-blocking.ts
+++ b/src/scripts/common/stop-blocking.ts
@@ -13,7 +13,7 @@ document.addEventListener("DOMContentLoaded", () => {
}
return proxiedBind.apply(this, Array.from(arguments) as any);
- }
+ };
const proxiedKeydown = $.prototype.keydown;
/** Proxies jQuery `.keydown()` so all key presses are allowed. */
@@ -21,7 +21,7 @@ document.addEventListener("DOMContentLoaded", () => {
arguments[0] = (_: any) => true;
return proxiedKeydown.apply(this, Array.from(arguments) as any);
- }
+ };
$.prototype.bind = proxiedBind;
$.prototype.keydown = proxiedKeydown;
diff --git a/src/scripts/pages/application-receipt/captcha.ts b/src/scripts/pages/application-receipt/captcha.ts
index c5bb657..94e6b0e 100644
--- a/src/scripts/pages/application-receipt/captcha.ts
+++ b/src/scripts/pages/application-receipt/captcha.ts
@@ -3,7 +3,11 @@
* stubs the form validation so the user can proceed without
* solving a CAPTCHA.
*/
+type WindowApplicationReceipt = {
+ validateForm?: () => boolean
+} & Window;
+
document.addEventListener("DOMContentLoaded", () => {
$("#werter > div > form > div:nth-child(4)").hide();
- (window as any).validateForm = () => true;
+ (window as WindowApplicationReceipt).validateForm = () => true;
});
diff --git a/src/scripts/pages/know-your-property/captcha.ts b/src/scripts/pages/know-your-property/captcha.ts
index 3abdf08..e304342 100644
--- a/src/scripts/pages/know-your-property/captcha.ts
+++ b/src/scripts/pages/know-your-property/captcha.ts
@@ -3,7 +3,11 @@
* stubs the captcha validation so the user can proceed without
* solving a CAPTCHA.
*/
+type WindowKnowYourProperty = {
+ validateCaptcha?: () => boolean
+} & Window;
+
document.addEventListener("DOMContentLoaded", () => {
$("#khatianPlotDiv > div:nth-child(6) > div").hide();
- (window as any).validateCaptcha = () => true;
+ (window as WindowKnowYourProperty).validateCaptcha = () => true;
});
diff --git a/src/scripts/pages/mutation-application/download-button.ts b/src/scripts/pages/mutation-application/download-button.ts
index 9503e00..6463079 100644
--- a/src/scripts/pages/mutation-application/download-button.ts
+++ b/src/scripts/pages/mutation-application/download-button.ts
@@ -1,4 +1,5 @@
import { PDFDocument, StandardFonts } from "pdf-lib";
+
import { observeDOM } from "@/shared/observe-dom";
const sanghaFacilitationCentreBannerUrl = "$l{ /assets/sangha-facilitation-centre-banner.jpg }l$";
@@ -17,7 +18,7 @@ observeDOM(() => {
submitButtonElement.on("click", (submitButtonClickEvent) => {
submitButtonClickEvent.preventDefault();
- (async () => {
+ void (async function(): Promise<void> {
const pdfDoc = await PDFDocument.load(await fetch("/BanglarBhumi/MutationDeclarationForm.action", {
method: "post",
credentials: "same-origin",
@@ -25,11 +26,13 @@ observeDOM(() => {
"Content-Type": "application/x-www-form-urlencoded"
},
body: "hdnAppNo="
- }).then(res => res.arrayBuffer()));
+ }).then((res) => res.arrayBuffer()));
const pages = pdfDoc.getPages();
const lastPage = pages[pages.length - 1];
- const { width, height: _ } = lastPage.getSize();
- const bannerImage = await pdfDoc.embedJpg(await fetch(sanghaFacilitationCentreBannerUrl).then(res => res.arrayBuffer()));
+ const { width } = lastPage.getSize();
+ const bannerImage
+ = await pdfDoc.embedJpg(await fetch(sanghaFacilitationCentreBannerUrl)
+ .then((res) => res.arrayBuffer()));
const bannerImageHeight = width * (bannerImage.height / bannerImage.width);
lastPage.drawImage(bannerImage, {
@@ -39,7 +42,7 @@ observeDOM(() => {
height: bannerImageHeight
});
- lastPage.drawText(pdfDoc.getCreationDate()!.toLocaleString(), {
+ lastPage.drawText(pdfDoc.getCreationDate()?.toLocaleString() ?? "", {
x: 10,
y: bannerImageHeight,
size: 12,
@@ -47,7 +50,7 @@ observeDOM(() => {
});
const link = document.createElement("a");
- link.href = window.URL.createObjectURL(new Blob([new Uint8Array(await pdfDoc.save())], {type: "application/pdf"}));
+ link.href = window.URL.createObjectURL(new Blob([new Uint8Array(await pdfDoc.save())], { type: "application/pdf" }));
link.download = "Declaration.pdf";
link.click();
})();
diff --git a/src/scripts/pages/sheet-map/index.ts b/src/scripts/pages/sheet-map/index.ts
index a4e45b0..c16a2ae 100644
--- a/src/scripts/pages/sheet-map/index.ts
+++ b/src/scripts/pages/sheet-map/index.ts
@@ -1,23 +1,23 @@
-import { generateWebPage } from "@/shared/generate-web-page";
import getDownloadMapPDFPageContent from "@/scripts/pages/sheet-map/download-map-pdf-page-content.html";
-import getMapPlotPolygonPathElement from "@/scripts/pages/sheet-map/map-plot-polygon-path-element.html";
import getMapPlotNumberLabelTextElement from "@/scripts/pages/sheet-map/map-plot-number-label-text-element.html";
+import getMapPlotPolygonPathElement from "@/scripts/pages/sheet-map/map-plot-polygon-path-element.html";
import getPlotInformationElement from "@/scripts/pages/sheet-map/plot-information-element.html";
+import { generateWebPage } from "@/shared/generate-web-page";
-interface PlotPolygon {
+type PlotPolygon = {
plotArea: number;
plotno: string;
- polygon: string;
+ polygon: string
};
-interface PlotNumberLabel {
+type PlotNumberLabel = {
plotno: string;
- point: string;
-}
+ point: string
+};
-const headerElement = document.querySelector("#headerTable > tbody > tr")!;
-const plotNumberInput = document.querySelector<HTMLInputElement>("#txtPlotNo")!;
-const plotInformation = document.createElement("div") as HTMLDivElement;
+const headerElement = document.querySelector<HTMLTableRowElement>("#headerTable > tbody > tr");
+const plotNumberInput = document.querySelector<HTMLInputElement>("#txtPlotNo");
+const plotInformation = document.createElement("div");
let plotPolygonPathElements = "";
let plotNumberLabelTextElements = "";
@@ -30,13 +30,14 @@ document.body.appendChild(plotInformation);
* @param text - The button label text.
* @returns The created button element.
*/
-const createHeaderButton = (text: string) => {
+function createHeaderButton(text: string): HTMLButtonElement {
const buttonContainer = document.createElement("td");
const button = document.createElement("button");
button.innerHTML = text;
button.style.display = "none";
buttonContainer.appendChild(button);
- headerElement.appendChild(buttonContainer);
+ if (headerElement)
+ headerElement.appendChild(buttonContainer);
return button;
};
@@ -46,14 +47,16 @@ const createHeaderButton = (text: string) => {
*
* @param plotPolygon - The selected plot's data, or `null`/`undefined` to clear.
*/
-const setPlotInformation = (plotPolygon: PlotPolygon | null | undefined = null) => {
- plotInformation.innerHTML = plotPolygon ? getPlotInformationElement({
- area: (plotPolygon.plotArea/1000).toFixed(3),
- plotNumber: plotPolygon.plotno
- }) : getPlotInformationElement({
- area: "0.000",
- plotNumber: ""
- });
+function setPlotInformation(plotPolygon: PlotPolygon | null | undefined = null): void {
+ plotInformation.innerHTML = plotPolygon
+ ? getPlotInformationElement({
+ area: (plotPolygon.plotArea / 1000).toFixed(3),
+ plotNumber: plotPolygon.plotno
+ })
+ : getPlotInformationElement({
+ area: "0.000",
+ plotNumber: ""
+ });
};
/**
@@ -62,11 +65,10 @@ const setPlotInformation = (plotPolygon: PlotPolygon | null | undefined = null)
*
* @param labelPoints - Whether to include plot number text labels.
*/
-const downloadPDF = (labelPoints: boolean = true) => {
+function downloadPDF(labelPoints = true): void {
/** Extracts a detail value (district/block/mouza) from the header table by column index. */
- const _getMapDetail = (i: number) => {
- const detail = document.querySelector(`#headerTable > tbody > tr > td:nth-child(${i})`)!
- .innerHTML
+ function _getMapDetail(i: number): string {
+ const detail = (document.querySelector<HTMLTableCellElement>(`#headerTable > tbody > tr > td:nth-child(${i.toString()})`)?.innerHTML ?? "")
.split("[")[1]
.trim();
return detail.substring(0, detail.length - 1);
@@ -85,33 +87,43 @@ const downloadPDF = (labelPoints: boolean = true) => {
const downloadPDFButton = createHeaderButton("SAVE PDF");
const downloadPDFNoLabelButton = createHeaderButton("SAVE PDF (NO LABEL)");
-downloadPDFButton.addEventListener("click", e => {
+downloadPDFButton.addEventListener("click", (e) => {
e.preventDefault();
downloadPDF();
});
-downloadPDFNoLabelButton.addEventListener("click", e => {
+downloadPDFNoLabelButton.addEventListener("click", (e) => {
e.preventDefault();
downloadPDF(false);
});
setPlotInformation();
-(async () => {
+void (async function(): Promise<void> {
const searchParams = new URLSearchParams(window.location.search);
- const response1 = await fetch(
- "/BanglarBhumi/sheetMap_populateLayerData?lstSheetNo=" + searchParams.get("lstSheetNo"),
+ const sheetMapLayerDataResponse = await fetch(
+ `/BanglarBhumi/sheetMap_populateLayerData?lstSheetNo=${searchParams.get("lstSheetNo")?.toString() ?? ""}`,
{
method: "POST"
});
- const plotPolygonList: PlotPolygon[] = (await response1.json()).features;
- const response2 = await fetch(
- "/BanglarBhumi/sheetMap_populateCentroidData?lstSheetNo=" + searchParams.get("lstSheetNo"),
+ type SheetMapLayerDataResponseType = {
+ features: PlotPolygon[]
+ };
+ const sheetMapLayerDataResponseJson
+ = await sheetMapLayerDataResponse.json() as SheetMapLayerDataResponseType;
+ const plotPolygonList: PlotPolygon[] = sheetMapLayerDataResponseJson.features;
+ const sheetMapCentroidDataResponse = await fetch(
+ `/BanglarBhumi/sheetMap_populateCentroidData?lstSheetNo=${searchParams.get("lstSheetNo")?.toString() ?? ""}`,
{
method: "POST"
});
- const plotNumberLabelList: PlotNumberLabel[] = (await response2.json()).features;
- let plotPolygons: { [key: string]: PlotPolygon } = {};
+ type SheetMapCentroidDataResponseType = {
+ features: PlotNumberLabel[]
+ };
+ const sheetMapCentroidDataResponseJson
+ = await sheetMapCentroidDataResponse.json() as SheetMapCentroidDataResponseType;
+ const plotNumberLabelList: PlotNumberLabel[] = sheetMapCentroidDataResponseJson.features;
+ const plotPolygons: Record<string, PlotPolygon> = {};
for (const plotPolygon of plotPolygonList) {
const plotPolygonPoints = plotPolygon.polygon.split("(((")[1].split(")))")[0];
@@ -132,10 +144,10 @@ setPlotInformation();
downloadPDFButton.style.display = "inherit";
downloadPDFNoLabelButton.style.display = "inherit";
- document.querySelector("#btnSearch")!.addEventListener("click", () => {
+ document.querySelector<HTMLButtonElement>("#btnSearch")?.addEventListener("click", () => {
let plotPolygon;
for (const p of plotPolygonList) {
- if (p.plotno === plotNumberInput.value) {
+ if (p.plotno === plotNumberInput?.value) {
plotPolygon = p;
break;
}
@@ -145,7 +157,7 @@ setPlotInformation();
await new Promise<void>((resolve, _reject) => {
const plotElementIdsControl = setInterval(() => {
- let plotElements = document.querySelector("#OpenLayers_Layer_Vector_25_vroot")?.children || [];
+ const plotElements = document.querySelector("#OpenLayers_Layer_Vector_25_vroot")?.children ?? [];
if (plotElements.length) {
clearInterval(plotElementIdsControl);
for (let i = 0; i < plotElements.length; i++) {
@@ -172,8 +184,8 @@ setPlotInformation();
*
* @param e - The mouse click event.
*/
- const handlePlotClick = (e: MouseEvent) => {
- document.querySelectorAll("path").forEach(e => {
+ function handlePlotClick(e: MouseEvent): void {
+ document.querySelectorAll("path").forEach((e) => {
e.setAttribute("fill", "#ffcc66");
});
diff --git a/src/scripts/pages/view-khatian/index.ts b/src/scripts/pages/view-khatian/index.ts
index 0be0c52..bb44a38 100644
--- a/src/scripts/pages/view-khatian/index.ts
+++ b/src/scripts/pages/view-khatian/index.ts
@@ -1,6 +1,6 @@
-import { generateWebPage } from "@/shared/generate-web-page";
-import { interceptPost } from "@/shared/intercept-jquery-ajax";
import getDownloadInformationPDFPageContent from "@/scripts/pages/view-khatian/download-information-pdf-page-content.html";
+import { generateWebPage } from "@/shared/generate-web-page";
+import { addPostInterceptor, JQueryAjaxArgs } from "@/shared/intercept-jquery-ajax";
const submitButtonElement = $("#khbutton");
const separatorElement = $("#bodycover > div > form > hr:nth-child(2)");
@@ -20,9 +20,9 @@ const styles = Array.from(submitButtonElementComputedStyles)
* @param selector - CSS selector for the select element.
* @returns The text of the selected option.
*/
-const getValueOfSelectElement = (selector: string) => {
- const element = document.querySelector<HTMLSelectElement>(selector)!;
- return element.options[element.selectedIndex].text;
+function getValueOfSelectElement(selector: string): string {
+ const element = document.querySelector<HTMLSelectElement>(selector);
+ return element?.options[element.selectedIndex].text ?? "";
};
let isPlotInformation: boolean | null = null;
@@ -31,11 +31,11 @@ let isPlotInformation: boolean | null = null;
* Opens a new window with a printable PDF view of the current khatian
* or plot details, including district/block/mouza info.
*/
-const downloadInformationPDF = () => {
+function downloadInformationPDF(): void {
generateWebPage(
getDownloadInformationPDFPageContent({
isPlotInformation: !!isPlotInformation,
- details: $(isPlotInformation ? "#plotdetails" : "#khdetails").html(),
+ details: $(isPlotInformation ? "#plotdetails" : "#khdetails").html() || "",
district: getValueOfSelectElement("#lstDistrictCode1"),
block: getValueOfSelectElement("#lstBlockCode1"),
mouza: getValueOfSelectElement("#lstMouzaList")
@@ -53,11 +53,11 @@ const downloadInformationPDF = () => {
*
* @param args - The `arguments` object from the intercepted `$.post` call.
*/
-const showDownloadButton = (args: any) => {
+function showDownloadButton(args: JQueryAjaxArgs): void {
if (isPlotInformation !== null) {
const callback = args[2];
- args[2] = (data: any) => {
- callback(data);
+ args[2] = (...data) => {
+ callback(...data);
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"
@@ -77,19 +77,19 @@ const showDownloadButton = (args: any) => {
formElement[0].insertBefore(downloadPDFButton[0], separatorElement[0]);
}
} else if (downloadPDFButton) {
- ($(downloadPDFButton as any) as any).remove();
+ ($(downloadPDFButton)).remove();
isPlotInformation = null;
downloadPDFButton = null;
}
- }
+ };
}
};
-interceptPost("plotDetailsAction_LandInfo.action", args => {
+addPostInterceptor("plotDetailsAction_LandInfo.action", (args: JQueryAjaxArgs) => {
isPlotInformation = true;
showDownloadButton(args);
});
-interceptPost("khDetailsAction_LandInfo.action", args => {
+addPostInterceptor("khDetailsAction_LandInfo.action", (args: JQueryAjaxArgs) => {
isPlotInformation = false;
showDownloadButton(args);
});