-
Notifications
You must be signed in to change notification settings - Fork 99
/
awscaptcha.js
165 lines (135 loc) · 4.79 KB
/
awscaptcha.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
(async () => {
function is_widget_frame() {
return document.querySelector('#captcha-container > #root #amzn-captcha-verify-button') !== null;
}
function is_image_frame() {
return document.querySelector('#captcha-container > #root #amzn-btn-audio-internal > img[title="Audio problem"]') !== null;
}
function is_audio_frame() {
return document.querySelector('#captcha-container > #root #amzn-btn-audio-internal > img[title="Visual problem"]') !== null;
}
async function on_widget_frame() {
try {
const $verify = document.querySelector('#captcha-container > #root #amzn-captcha-verify-button');
if ($verify) {
$verify.click();
}
} catch (e) {
console.log('error on_widget_frame', e);
}
}
async function on_image_frame() {
try {
const $e = document.querySelector('#captcha-container > #root #amzn-btn-audio-internal');
if ($e) {
$e.click();
}
} catch (e) {
console.log('error on_image_frame', e);
}
}
function get_audio_data() {
try {
const $audio = document.querySelector('audio');
const data = $audio.src.replace('data:audio/aac;base64,', '');
return data;
} catch (e) {
console.log('error get_audio_data', e);
}
return null;
}
let last_audio_data = null;
function on_task_ready(i=500) {
return new Promise(resolve => {
let checking = false;
const check_interval = setInterval(async () => {
if (checking) {
return;
}
checking = true;
const settings = await BG.exec('Settings.get');
if (!settings.enabled || !settings.awscaptcha_auto_solve) {
return;
}
const input = document.querySelector('input[placeholder="Answer"]');
if (!input || input.value !== '') {
checking = false;
return;
}
const audio_data = get_audio_data();
if (!audio_data) {
checking = false;
return;
}
if (last_audio_data === audio_data) {
checking = false;
return;
}
last_audio_data = audio_data;
clearInterval(check_interval);
checking = false;
return resolve({input, audio_data});
}, i);
});
}
async function on_audio_frame() {
const {input, audio_data} = await on_task_ready();
if (input === null || audio_data === null) {
return;
}
const settings = await BG.exec('Settings.get');
if (!settings.enabled || !settings.awscaptcha_auto_solve) {
return;
}
const solve_start = Time.time();
// Detect images
const {job_id, data} = await NopeCHA.post({
captcha_type: IS_DEVELOPMENT ? 'awscaptcha_dev' : 'awscaptcha',
audio_data: [audio_data],
key: settings.key,
});
if (!data || data.length === 0) {
document.querySelector('#amzn-btn-refresh-internal')?.click();
await Time.sleep(200);
last_audio_data = null;
return;
}
let delay = parseInt(settings.awscaptcha_solve_delay_time);
delay = delay ? delay : 1000;
const delta = settings.awscaptcha_solve_delay ? (delay - (Time.time() - solve_start)) : 0;
if (delta > 0) {
await Time.sleep(delta);
}
// Solve
if (data[0].length === 0) {
document.querySelector('#amzn-btn-refresh-internal')?.click();
await Time.sleep(200);
last_audio_data = null;
}
else {
input.value = data[0];
await Time.sleep(200);
document.querySelector('#amzn-btn-verify-internal')?.click();
}
}
while (true) {
await Time.sleep(1000);
const settings = await BG.exec('Settings.get');
if (!settings || !settings.enabled) {
continue;
}
const hostname = await Location.hostname();
if (settings.disabled_hosts.includes(hostname)) {
continue;
}
if (settings.awscaptcha_auto_open && is_widget_frame()) {
await on_widget_frame();
}
else if (settings.hcaptcha_auto_solve && is_image_frame()) {
await on_image_frame();
}
else if (settings.hcaptcha_auto_solve && is_audio_frame()) {
await on_audio_frame();
}
}
})();