Update script to handle new captcha format
This commit is contained in:
parent
daa4c422d0
commit
461186e252
2 changed files with 65 additions and 9 deletions
26
README.md
26
README.md
|
@ -1,6 +1,28 @@
|
||||||
# skillrack-captcha-solver
|
# skillrack-captcha-solver
|
||||||
Captcha solver for skillrack.
|
## Captcha solver for skillrack.
|
||||||
|
|
||||||
Use GreaseMonkey/TamperMonkey to run the script.
|
Use GreaseMonkey/TamperMonkey to run the script.
|
||||||
|
|
||||||
__Note:__ 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.
|
> ⚠️ **Please disable the script if you are attending the 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.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Optional username parsing
|
||||||
|
|
||||||
|
**You don't need to do this unless you see a warning asking you to do so.**
|
||||||
|
|
||||||
|
The script handles most of the username checking by itself, but if it fails to do so and gives an alert instead, replace the `USERNAME` variable on the top of the script from the string the alert gives.
|
||||||
|
|
||||||
|
For example, if the alert says
|
||||||
|
```
|
||||||
|
STRING RECOGNISED: bch12xyz232@abcd 123+456=
|
||||||
|
```
|
||||||
|
|
||||||
|
change the first line as
|
||||||
|
```js
|
||||||
|
const USERNAME = "bch12xyz232@abcd";
|
||||||
|
```
|
||||||
|
and save the script.
|
|
@ -7,16 +7,18 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Skillrack Captcha Solver
|
// @name Skillrack Captcha Solver
|
||||||
// @namespace https://github.com/adithyagenie/skillrack-captcha-solver
|
// @namespace https://github.com/adithyagenie/skillrack-captcha-solver
|
||||||
// @version 0.4
|
// @version 0.5
|
||||||
// @description Solves math captcha in SkillRack using Tesseract.js
|
// @description Solves math captcha in SkillRack using Tesseract.js
|
||||||
// @author adithyagenie
|
// @author adithyagenie
|
||||||
// @license AGPL-3.0-or-later
|
// @license AGPL-3.0-or-later
|
||||||
// @include https://www.skillrack.com/faces/candidate/codeprogram.xhtml
|
// @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/tutorprogram.xhtml
|
||||||
// @include https://www.skillrack.com/faces/candidate/codeprogramgroup.xhtml
|
// @include https://www.skillrack.com/faces/candidate/codeprogramgroup.xhtml
|
||||||
// @require https://cdn.jsdelivr.net/npm/tesseract.js@5.0.0/dist/tesseract.min.js
|
// @require https://cdn.jsdelivr.net/npm/tesseract.js@5.0.2/dist/tesseract.min.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
|
const USERNAME = "";
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
@ -74,12 +76,12 @@
|
||||||
window.location.href ==
|
window.location.href ==
|
||||||
"https://www.skillrack.com/faces/candidate/codeprogram.xhtml"
|
"https://www.skillrack.com/faces/candidate/codeprogram.xhtml"
|
||||||
)
|
)
|
||||||
image = document.getElementById("j_id_6s");
|
image = document.getElementById("j_id_6x");
|
||||||
else if (
|
else if (
|
||||||
window.location.href ==
|
window.location.href ==
|
||||||
"https://www.skillrack.com/faces/candidate/tutorprogram.xhtml"
|
"https://www.skillrack.com/faces/candidate/tutorprogram.xhtml"
|
||||||
)
|
)
|
||||||
image = document.getElementById("j_id_5j");
|
image = document.getElementById("j_id_5o");
|
||||||
|
|
||||||
const textbox = document.getElementById("capval");
|
const textbox = document.getElementById("capval");
|
||||||
const button = document.getElementById("proceedbtn");
|
const button = document.getElementById("proceedbtn");
|
||||||
|
@ -101,7 +103,7 @@
|
||||||
}
|
}
|
||||||
sessionStorage.setItem("captchaFail", "true");
|
sessionStorage.setItem("captchaFail", "true");
|
||||||
console.log("Detected failed attempt at solving captcha");
|
console.log("Detected failed attempt at solving captcha");
|
||||||
const back = document.getElementById("j_id_5r");
|
const back = document.getElementById("j_id_5s");
|
||||||
back.click();
|
back.click();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +129,33 @@
|
||||||
return canvas.toDataURL();
|
return canvas.toDataURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove username from captcha
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} text
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function removeText(text) {
|
||||||
|
text = text.replace(USERNAME, "");
|
||||||
|
let i = text.length - 1;
|
||||||
|
|
||||||
|
i = text.lastIndexOf("+")
|
||||||
|
if (i == -1) {
|
||||||
|
console.error("Error parsing username.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
|
||||||
|
for (i; i >= 0; i--) {
|
||||||
|
if (!("1234567890".includes(text[i]))) {
|
||||||
|
return text.slice(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.error("Error parsing username.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Parse OCR result and solve the problem
|
// Parse OCR result and solve the problem
|
||||||
function getNums(text) {
|
function getNums(text) {
|
||||||
const a = text.replace(" ", "").replace("=", "").split("+");
|
const a = text.replace(" ", "").replace("=", "").split("+");
|
||||||
|
@ -137,14 +166,19 @@
|
||||||
console.log(`Converting image: ${new Date().getTime() - time} ms.`);
|
console.log(`Converting image: ${new Date().getTime() - time} ms.`);
|
||||||
// Image Processing with Tesseract.js
|
// Image Processing with Tesseract.js
|
||||||
Tesseract.recognize(invertedimg, "eng", {
|
Tesseract.recognize(invertedimg, "eng", {
|
||||||
whitelist: "1234567890+=",
|
whitelist: "1234567890+=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@ ",
|
||||||
psm: 7,
|
psm: 7,
|
||||||
})
|
})
|
||||||
.then(({ data: { text } }) => {
|
.then(({ data: { text } }) => {
|
||||||
console.log(`OCR: ${new Date().getTime() - time} ms.`);
|
console.log(`OCR: ${new Date().getTime() - time} ms.`);
|
||||||
// Solve the Math Problem
|
// Solve the Math Problem
|
||||||
try {
|
try {
|
||||||
const result = getNums(text);
|
const mathprob = removeText(text);
|
||||||
|
const result = getNums(mathprob);
|
||||||
|
if (isNaN(result)) {
|
||||||
|
alert(`Unable to solve math captcha... Check the readme file on https://github.com/adithyagenie/skillrack-captcha-solver for instructions on optional username parsing.\n\nSTRING RECOGNISED: ${text}`)
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log(
|
console.log(
|
||||||
"Found math captcha. Auto-filling answer: ",
|
"Found math captcha. Auto-filling answer: ",
|
||||||
result
|
result
|
||||||
|
|
Loading…
Reference in a new issue