Skip to content

Instantly share code, notes, and snippets.

@mantou132
Last active November 17, 2019 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mantou132/49fb0e3649219d8dd2e62d4e0fb1bfc5 to your computer and use it in GitHub Desktop.
Save mantou132/49fb0e3649219d8dd2e62d4e0fb1bfc5 to your computer and use it in GitHub Desktop.
网站视频培训自动验证
document.querySelector('#videoVerifyContent').remove();
async function validator() {
const ocr = async url => {
const { default: Tesseract } = await import(
"https://dev.jspm.io/tesseract.js"
);
const data = await Tesseract.recognize(
url ||
"https://ware.cdeledu.com/cdel_ware/common/makeArithmeticCode.shtm?random=0.6212206602916508"
);
const str = data.text
.trim()
.replace("l", "1")
.replace(/o|O/, "0")
.replace(/:|=/, "")
.replace(/x|X/, "*");
console.log(str, eval(str));
return eval(str);
};
/**
* @type HTMLImageElement
*/
const img = document.querySelector("#verificationCode");
const canvas = document.createElement("canvas");
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
canvas.getContext("2d").drawImage(img, 0, 0);
const url = canvas.toDataURL();
let result;
try {
result = await ocr(url);
} catch (err) {
img.click();
setTimeout(validator, 1000);
throw new Error("validator fail");
}
/**
* @type HTMLInputElement
*/
const input = document.querySelector("#userAnswer");
input.value = result;
/**
* @type HTMLButtonElement
*/
const btn = document.querySelector("button.jbox-button");
btn.click();
}
new MutationObserver(() => {
if (document.querySelector('#jbox')) validator().catch(() => location.reload());
}).observe(document.body, {
attributes: true,
childList: true,
subtree: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment