From c530eadda9361ac2f05343025091daf84c5328d0 Mon Sep 17 00:00:00 2001 From: adithyagenie Date: Thu, 7 Mar 2024 19:53:03 +0530 Subject: [PATCH] Bump tesseract.js to v5.0.5 Signed-off-by: adithyagenie --- README.md | 2 +- userscript.js | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7100ae2..702eb2e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Use GreaseMonkey/TamperMonkey to run the script. -> ⚠️ **Please disable the script if you are attending the test as it might lead to unintended effects.** +> ⚠️ **Please disable the script if you are attending a test as it might lead to unintended effects.** > ⚠️ **Attempting to navigate the page while the captcha solver is running may lead to unintended effects. If it gets stuck in a loop, closing and opening the tabs will fix it.** diff --git a/userscript.js b/userscript.js index 17f28e8..8138009 100644 --- a/userscript.js +++ b/userscript.js @@ -11,10 +11,8 @@ // @description Solves math captcha in SkillRack using Tesseract.js // @author adithyagenie // @license AGPL-3.0-or-later -// @include /https:\/\/(www.)?skillrack\.com\/faces\/candidate\/codeprogram\.xhtml/ -// @include /https:\/\/(www.)?skillrack\.com\/faces\/candidate\/tutorprogram\.xhtml/ -// @include /https:\/\/(www.)?skillrack\.com\/faces\/candidate\/codeprogramgroup\.xhtml/ -// @require https://cdn.jsdelivr.net/npm/tesseract.js@5.0.2/dist/tesseract.min.js +// @include /https:\/\/(www\.)?skillrack\.com\/faces\/candidate\/(codeprogram|tutorprogram|codeprogramgroup)\.xhtml/ +// @require https://cdn.jsdelivr.net/npm/tesseract.js@5.0.5/dist/tesseract.min.js // ==/UserScript== const USERNAME = ""; @@ -135,21 +133,20 @@ const USERNAME = ""; // Remove username from captcha /** - * - * @param {string} text - * @returns + * + * @param {string} text + * @returns */ function removeText(text) { text = text.replace(USERNAME, ""); let i = text.length - 1; - - i = text.lastIndexOf("+") + i = text.lastIndexOf("+"); if (i == -1) { + alert("Oops! I wasn't able to parse the captcha correctly :( Please enter the captcha or try re-visitng again!"); console.error("Error parsing username."); return; } i--; - for (i; i >= 0; i--) { if (!("1234567890".includes(text[i]))) { return text.slice(i + 1); @@ -171,10 +168,10 @@ const USERNAME = ""; // Image Processing with Tesseract.js Tesseract.recognize(invertedimg, "eng", { whitelist: "1234567890+=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@ ", - psm: 7, + psm: 6, }) .then(({ data: { text } }) => { - console.log(`OCR: ${new Date().getTime() - time} ms.`); + console.log(`OCR: ${new Date().getTime() - time} ms. Result: ${text}`); // Solve the Math Problem try { const mathprob = removeText(text);