-
Notifications
You must be signed in to change notification settings - Fork 99
/
funcaptcha_scrape.js
102 lines (87 loc) · 3.66 KB
/
funcaptcha_scrape.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
(async () => {
const RELOAD_ON_SOLVED = IS_DEVELOPMENT; // If true, restart captcha to scrape more data
const SUBMISSION_STRATEGY = 'lazy';
window.nopecha = []; // Lazy cache
const listeners = {}; // Click listeners
function get_task() {
const $task = document.querySelector('#game_children_text > h2') || document.querySelector('#game-header');
return $task?.innerText?.trim();
}
function get_image() {
const $image = document.querySelector('img#game_challengeItem_image') || document.querySelector('#challenge-image');
return $image?.src?.split(';base64,')[1];
}
async function on_click(index) {
const task = get_task();
const image = get_image();
if (task && image) {
const url = (await BG.exec('Tab.info'))?.url;
const data = {task, image, index, url};
if (SUBMISSION_STRATEGY.startsWith('l')) {
window.parent.postMessage({nopecha: true, action: 'append', data: data}, '*');
}
if (SUBMISSION_STRATEGY.startsWith('e')) {
await Net.fetch('https://api.nopecha.com/upload', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data),
});
}
}
}
const event_method = window.addEventListener ? 'addEventListener' : 'attachEvent';
const message_event = event_method == 'attachEvent' ? 'onmessage' : 'message';
window[event_method](message_event, async e => {
const key = e.message ? 'message' : 'data';
const data = e[key];
if (data && data.nopecha === true) {
if (data.action === 'append') {
window.nopecha.push(data.data);
}
else if (data.action === 'clear') {
window.nopecha = [];
}
else if (data.action === 'reload') {
window.parent.postMessage({nopecha: true, action: 'reload'}, '*');
window.location.reload(true);
}
}
}, false);
while (true) {
await Time.sleep(1000);
try {
const $success = document.querySelector('body.victory');
if ($success) {
const proms = [];
for (const data of window.nopecha) {
const prom = Net.fetch('https://api.nopecha.com/upload', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data),
});
proms.push(prom);
}
await Promise.all(proms);
window.nopecha = [];
if (RELOAD_ON_SOLVED) {
window.parent.postMessage({nopecha: true, action: 'reload'}, '*');
window.location.reload(true);
}
}
const $timeout = document.querySelector('#timeout_widget');
if ($timeout?.style?.display === 'block') {
window.parent.postMessage({nopecha: true, action: 'reload'}, '*');
window.location.reload(true);
}
const $btns = document.querySelectorAll('#game_children_challenge ul > li > a');
for (const i in $btns) {
const $e = $btns[i];
if (i in listeners) {
$e.removeEventListener('click', listeners[i]);
}
listeners[i] = on_click.bind(this, parseInt(i));
$e.addEventListener('click', listeners[i]);
}
} catch (e) {}
}
})();