Skip to content

Commit bf304de

Browse files
committed
add disabled hosts
1 parent b572421 commit bf304de

19 files changed

Lines changed: 1190 additions & 170 deletions

‎awscaptcha.js‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
return document.querySelector('#captcha-container > #root #amzn-captcha-verify-button') !== null;
44
}
55

6+
67
function is_image_frame() {
78
return document.querySelector('#captcha-container > #root #amzn-btn-audio-internal > img[title="Audio problem"]') !== null;
89
}
910

11+
1012
function is_audio_frame() {
1113
return document.querySelector('#captcha-container > #root #amzn-btn-audio-internal > img[title="Visual problem"]') !== null;
1214
}
1315

16+
1417
async function on_widget_frame() {
1518
try {
1619
const $verify = document.querySelector('#captcha-container > #root #amzn-captcha-verify-button');
@@ -22,6 +25,7 @@
2225
}
2326
}
2427

28+
2529
async function on_image_frame() {
2630
try {
2731
const $e = document.querySelector('#captcha-container > #root #amzn-btn-audio-internal');
@@ -33,6 +37,7 @@
3337
}
3438
}
3539

40+
3641
function get_audio_data() {
3742
try {
3843
const $audio = document.querySelector('audio');
@@ -44,6 +49,7 @@
4449
return null;
4550
}
4651

52+
4753
let last_audio_data = null;
4854
function on_task_ready(i=500) {
4955
return new Promise(resolve => {
@@ -84,6 +90,7 @@
8490
});
8591
}
8692

93+
8794
async function on_audio_frame() {
8895
const {input, audio_data} = await on_task_ready();
8996

@@ -129,10 +136,9 @@
129136
await Time.sleep(200);
130137
document.querySelector('#amzn-btn-verify-internal')?.click();
131138
}
132-
133-
// last_audio_data = null;
134139
}
135140

141+
136142
while (true) {
137143
await Time.sleep(1000);
138144

@@ -141,6 +147,11 @@
141147
continue;
142148
}
143149

150+
const hostname = await Location.hostname();
151+
if (settings.disabled_hosts.includes(hostname)) {
152+
continue;
153+
}
154+
144155
if (settings.awscaptcha_auto_open && is_widget_frame()) {
145156
await on_widget_frame();
146157
}

‎background.js‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class Settings {
9696

9797
static load() {
9898
return new Promise(resolve => {
99-
let storage = bapi.browser.storage;
100-
if (!storage) { // Browsers such as chromium
99+
const storage = bapi.browser.storage;
100+
if (!storage) {
101101
resolve();
102102
return;
103103
}
@@ -109,14 +109,15 @@ class Settings {
109109
Settings.data = settings;
110110
if (Settings.data.version !== SettingsManager.DEFAULT.version) {
111111
const key = Settings.data.key;
112+
console.log('mismatched version', key);
112113
await Settings.reset();
113114
Settings.data.key = key;
114115
}
115116
}
116-
// Temporary fix
117-
if (Settings.data.key?.startsWith('MIIBI')) {
118-
Settings.data.key = '';
119-
}
117+
// // Temporary fix
118+
// if (Settings.data.key?.startsWith('MIIBI')) {
119+
// Settings.data.key = '';
120+
// }
120121
resolve();
121122
});
122123
});
@@ -173,12 +174,14 @@ class Injector {
173174

174175
static async inject_files({tab_id, frame_id, data: {files}}) {
175176
const options = {
176-
// target: {tabId: tab_id, allFrames: true},
177177
target: {tabId: tab_id, frameIds: [frame_id]},
178178
world: 'MAIN',
179179
injectImmediately: true,
180180
files: files,
181181
};
182+
if (bapi.VERSION === 'firefox') {
183+
delete options.world;
184+
}
182185
return await Injector._inject(options);
183186
}
184187
}
@@ -194,13 +197,13 @@ class Recaptcha {
194197

195198
class Server {
196199
static ENDPOINT = `https://api.nopecha.com/status?v=${bapi.browser.runtime.getManifest().version}`;
197-
static in_progress = false;
200+
static is_fetching_plan = false;
198201

199202
static async get_plan({data: {key}}) {
200-
if (Server.in_progress) {
203+
if (Server.is_fetching_plan) {
201204
return false;
202205
}
203-
Server.in_progress = true;
206+
Server.is_fetching_plan = true;
204207
let plan = {
205208
plan: 'Unknown',
206209
credit: 0,
@@ -212,7 +215,7 @@ class Server {
212215
const r = await fetch(`${Server.ENDPOINT}&k=${key}`);
213216
plan = JSON.parse(await r.text());
214217
} catch {}
215-
Server.in_progress = false;
218+
Server.is_fetching_plan = false;
216219
return plan;
217220
}
218221
}
@@ -315,6 +318,13 @@ class Icon {
315318
}
316319

317320

321+
class Browser {
322+
static async get_version() {
323+
return bapi.VERSION;
324+
}
325+
}
326+
327+
318328
const FN = {
319329
set_cache: Cache.set,
320330
get_cache: Cache.get,
@@ -349,6 +359,8 @@ const FN = {
349359

350360
set_icon: Icon.set_icon,
351361
// set_badge: Icon.set_badge,
362+
363+
browser_version: Browser.get_version,
352364
};
353365

354366

@@ -366,16 +378,22 @@ const FN = {
366378
// Chrome doesn't support async event listeners yet
367379
(async () => {
368380
const verbose = !['get_settings', 'set_settings', 'set_cache'].includes(req.method);
381+
// const verbose = !['set_cache'].includes(req.method);
369382

370383
if (verbose) {
371384
console.log('message', sender, req);
372385
}
373386

387+
let tab_id = sender?.tab?.id;
388+
if (req.data && 'tab_id' in req.data) {
389+
tab_id = req.data.tab_id;
390+
}
391+
374392
try{
375393
// const result = await FN[req.method]({tab_id: sender?.tab?.id, data: req.data});
376-
const result = await FN[req.method]({tab_id: sender?.tab?.id, frame_id: sender?.frameId, data: req.data});
394+
const result = await FN[req.method]({tab_id, frame_id: sender?.frameId, data: req.data});
377395
if (verbose){
378-
console.log('result', result);
396+
console.log('result', req.method, result);
379397
}
380398
return result;
381399
} catch (e) {

‎build.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ def build():
231231
extension_manifest.update(specific_manifest)
232232

233233
# Remove Firefox gecko ID for production
234-
with contextlib.suppress(KeyError):
235-
del extension_manifest['browser_specific_settings']['gecko']['id']
234+
# if zip:
235+
# with contextlib.suppress(KeyError):
236+
# del extension_manifest['browser_specific_settings']['gecko']['id']
236237

237238
manifest_content = json.dumps(extension_manifest, indent=4)
238239
(export_directory / "manifest.json").write_text(manifest_content)

‎content.js‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ class Net {
1919
}
2020

2121

22+
class Script {
23+
static inject_file(file) {
24+
return new Promise(resolve => {
25+
const $script = document.createElement('script');
26+
$script.src = chrome.runtime.getURL(file);
27+
$script.onload = resolve;
28+
(document.head || document.documentElement).appendChild($script);
29+
});
30+
}
31+
}
32+
33+
34+
class Location {
35+
static async hostname() {
36+
const tab = await BG.exec('info_tab');
37+
const tab_url = tab.url ? tab.url : 'Unknown Host';
38+
return tab.url?.replace(/^(.*:)\/\/([A-Za-z0-9\-\.]+)(:[0-9]+)?(.*)$/, '$2');
39+
}
40+
}
41+
42+
2243
class Image {
2344
static encode(url) {
2445
return new Promise(resolve => {
@@ -147,7 +168,7 @@ class NopeCHA {
147168
break;
148169
}
149170

150-
await Time.sleep(500);
171+
await Time.sleep(1000);
151172
const text = await Net.fetch(`${NopeCHA.INFERENCE_URL}?id=${job_id}&key=${key}`);
152173
try {
153174
const r = JSON.parse(text);
@@ -161,7 +182,7 @@ class NopeCHA {
161182
return {job_id, data: r.data, metadata: r.metadata};
162183
} catch (e) {
163184
console.log('failed to parse server response for solution', e);
164-
break;
185+
// break;
165186
}
166187
}
167188

‎funcaptcha.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@
154154
continue;
155155
}
156156

157+
const hostname = await Location.hostname();
158+
if (settings.disabled_hosts.includes(hostname)) {
159+
continue;
160+
}
161+
157162
if (settings.funcaptcha_auto_open && is_widget_frame()) {
158163
await on_widget_frame();
159164
}

‎funcaptcha_demo.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
open_frame_token('ea signin', 0, 1);
210210
// open_frame_token('myprepaidcenter', 0, 1);
211211
open_frame_token('twitter', 0, 1);
212-
open_frame_token('discoveryplus', 0, 1);
212+
// open_frame_token('discoveryplus', 0, 1);
213213
open_frame_token('minecraft', 0, 1);
214214
// open_frame_token('rblxwild', 0, 1);
215215
open_frame_token('imvu', 0, 1);

‎hcaptcha.js‎

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,27 @@
244244
continue;
245245
}
246246

247-
if (!hooking) {
247+
const hostname = await Location.hostname();
248+
if (settings.disabled_hosts.includes(hostname)) {
249+
continue;
250+
}
251+
252+
if (!hooking && hook === null) {
253+
window.addEventListener('message', e => {
254+
if (e.data.event === 'nopecha_hook') {
255+
hook = event.source;
256+
}
257+
});
258+
248259
if (window.location.hash.includes('frame=challenge')) {
249260
hooking = true;
250-
window.addEventListener('message', event => {
251-
if (event.data.event === 'nopecha_hook') {
252-
hook = event.source;
253-
}
254-
});
255-
await BG.exec('inject_files', {files: ['hcaptcha_hook.js']});
261+
const browser_version = await BG.exec('browser_version');
262+
if (browser_version === 'firefox') {
263+
await Script.inject_file('hcaptcha_hook.js');
264+
}
265+
else {
266+
await BG.exec('inject_files', {files: ['hcaptcha_hook.js']});
267+
}
256268
}
257269
}
258270

@@ -263,4 +275,76 @@
263275
await on_image_frame();
264276
}
265277
}
278+
279+
// function show_progress() {
280+
// const sheet = document.body.appendChild(document.createElement('style')).sheet;
281+
// sheet.insertRule(`#nopecha_progress {
282+
// background: #222;
283+
// position: absolute;
284+
// top: 0;
285+
// right: 0;
286+
// min-width: 70px;
287+
// min-height: 70px;
288+
// z-index: 9999;
289+
// }`, 0);
290+
// sheet.insertRule(`.progressbar {
291+
// position: relative;
292+
// width: 70px;
293+
// height: 70px;
294+
// transform: rotate(-90deg);
295+
// }`, 1);
296+
// sheet.insertRule(`.progressbar > svg {
297+
// position: absolute;
298+
// width: 70px;
299+
// height: 70px;
300+
// top: 0;
301+
// bottom: 0;
302+
// left: 0;
303+
// right: 0;
304+
// }`, 2);
305+
// sheet.insertRule(`.progressbar > svg > circle {
306+
// position: relative;
307+
// width: 70px;
308+
// height: 70px;
309+
// fill: none;
310+
// stroke: #fff;
311+
// stroke-width: 2;
312+
// stroke-dasharray: 440;
313+
// stroke-dashoffset: 440;
314+
// stroke-linecap: round;
315+
// transform: translate(5px, 5px);
316+
// -webkit-animation: anim_circle 3s linear forwards;
317+
// animation: anim_circle 3s linear forwards;
318+
// filter: drop-shadow(0 0 5px #ff33ff);
319+
// z-index: 999;
320+
// }`, 3);
321+
// sheet.insertRule(`.progressbar__text {
322+
// color: #ff33ff;
323+
// position: absolute;
324+
// top: 50%;
325+
// left: 50%;
326+
// padding: 0.25em 0.5em;
327+
// border-radius: 0.25em;
328+
// font-size: 12px;
329+
// line-height: 12px;
330+
// text-align: center;
331+
// transform: translate(-50%, -50%) rotate(90deg);
332+
// }`, 4);
333+
// sheet.insertRule(`@-webkit-keyframes anim_circle {to {stroke-dashoffset: 0;}}`, 5);
334+
// sheet.insertRule(`@keyframes anim_circle {to {stroke-dashoffset: 0;}}`, 6);
335+
336+
// const $svg = document.createElement('svg');
337+
// $svg.innerHTML = '<circle cx="30" cy="30" r="25"> </circle>'
338+
// const $text = document.createElement('span');
339+
// $text.classList.add('progressbar__text');
340+
// $text.innerHTML = 'Solve';
341+
// const $p = document.createElement('div');
342+
// $p.classList.add('progressbar');
343+
// $p.append($svg);
344+
// $p.append($text);
345+
// const $nopecha_progress = document.createElement('div');
346+
// $nopecha_progress.id = 'nopecha_progress';
347+
// $nopecha_progress.append($p);
348+
// document.body.append($nopecha_progress);
349+
// }
266350
})();

0 commit comments

Comments
 (0)