aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/login
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2025-06-14 01:40:18 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2025-06-14 01:40:18 +0530
commit54467df36805eabf9113d1bb84d7434b331cd167 (patch)
treea13b48386e20bf69e7ede0bfff4715c17b90549d /src/scripts/login
parent7164ef595147d997068b953d0e8bd19add0db5f9 (diff)
downloadbanglar-bhumi-utils-54467df36805eabf9113d1bb84d7434b331cd167.tar.gz
banglar-bhumi-utils-54467df36805eabf9113d1bb84d7434b331cd167.zip
Successfully performing OCR on the captcha image and autofilling it for login.
Diffstat (limited to 'src/scripts/login')
-rw-r--r--src/scripts/login/index.ts37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/scripts/login/index.ts b/src/scripts/login/index.ts
index b7e0a73..6e459a5 100644
--- a/src/scripts/login/index.ts
+++ b/src/scripts/login/index.ts
@@ -54,7 +54,7 @@ const observer = new MutationObserver((mutationsList, obs) => {
for (const node of mutation.addedNodes) {
if ((node as any).nodeType === 1 && (node as any).id === "loginform") {
const img = (node as HTMLFormElement).querySelector("#captchaImg") as HTMLImageElement;
- const captchaInput = (node as HTMLFormElement).querySelector("txtInput") as HTMLInputElement;
+ const captchaInput = (node as HTMLFormElement).querySelector("#txtInput") as HTMLInputElement;
// Wait for image to load to get correct dimensions
img.addEventListener("load", async () => {
@@ -83,26 +83,21 @@ const observer = new MutationObserver((mutationsList, obs) => {
prepareCaptcha(ctx, canvas.width, canvas.height);
canvas.style.display = "";
const dataURL = canvas.toDataURL("image/png");
- chrome.runtime.sendMessage({ type: "OCR", dataURL }, console.log);
- // TODO: Perform OCR
- // window.postMessage({
- // type: "RUN_OCR",
- // dataURL: dataURL
- // }, "*");
- //
- // // Listen for OCR result
- // function recieveOCRResult(event: any) {
- // if (event.data.type === "OCR_RESULT") {
- // console.log("Tesseract result:", event.data.text, "Confidence:", event.data.confidence);
- // window.removeEventListener("message", recieveOCRResult);
- // if (event.data.confidence < 80 || event.data.text.length !== 6) {
- // img.src = "generateCaptcha?" + new Date().getTime();
- // } else {
- // captchaInput.value = event.data.text;
- // }
- // }
- // }
- // window.addEventListener("message", recieveOCRResult);
+
+ // Perform OCR
+ chrome.runtime.sendMessage(
+ { type: "OCR", dataURL },
+ ({ success, text, confidence }) => {
+ if (success) {
+ if (confidence < 85) {
+ // Reset the captcha if confidence is low
+ img.src = "generateCaptcha?" + new Date().getTime();
+ } else {
+ captchaInput.value = text;
+ }
+ }
+ },
+ );
});
}
}