-
Notifications
You must be signed in to change notification settings - Fork 1
/
captcha-notifier.js
71 lines (57 loc) · 2.13 KB
/
captcha-notifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let lastNotificationSent = new Date();
//let solvingCaptcha = false;
setInterval(async () => {
if (!document.querySelector('#captcha_form')){
return;
}
/* if (solvingCaptcha) {
return;
}*/
if (document.querySelector('#captcha_form').style.display === "block") {
// 20 seconds between each notification
if ((new Date().getTime() / 1000) - (lastNotificationSent.getTime() / 1000) >= 20) {
notify("RMA_CAPTCHA_ACTIVE");
lastNotificationSent = new Date();
}
/*solvingCaptcha = true;
const backgroundImageStyle = document.querySelector("#captcha_form_content #captcha_img_div").style.backgroundImage;
const regex = /url\("(?<base64>data:image\/jpeg\;base64.+)\"\)/m;
const matches = backgroundImageStyle.match(regex);
if (!matches) {
solvingCaptcha = false;
return;
}
const solution = await solveCaptcha(matches.groups.base64).catch(e => {
solvingCaptcha = false;
});
// Type captcha and submit
document.getElementById("captcha_input").value = solution;
Captcha.submit();
solvingCaptcha = false;*/
}
}, 2000);
const solveCaptcha = async (base64) => new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:3000/tasks", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
img: base64,
token: ""
}));
xhr.onload = function async () {
let data = JSON.parse(this.responseText);
setTimeout(async () => {
let xhr = new XMLHttpRequest();
xhr.open("POST", `http://localhost:3000/result/${data.taskId}`, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
token: ""
}));
xhr.onload = function async () {
const data = JSON.parse(xhr.responseText);
solvingCaptcha = false;
resolve(data.solution);
}
}, 20000);
}
});