Last active
November 17, 2019 11:31
-
-
Save mantou132/49fb0e3649219d8dd2e62d4e0fb1bfc5 to your computer and use it in GitHub Desktop.
网站视频培训自动验证
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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