diff --git a/background.js b/background.js index 85276cc..9dc060c 100644 --- a/background.js +++ b/background.js @@ -123,38 +123,66 @@ class Settings { static data = {}; static _save() { - return new Promise(resolve => bapi.browser.storage.sync.set({settings: Settings.data}, resolve)); + console.log('Settings.save', Settings.data); + return new Promise(resolve => { + bapi.browser.storage.sync.set({settings: Settings.data}, resolve); + }); } - static load() { + // static load() { + // return new Promise(resolve => { + // const storage = bapi.browser.storage; + // if (!storage) { + // resolve(); + // return; + // } + // storage.sync.get(['settings'], async ({settings}) => { + // if (!settings) { + // await Settings.reset(); + // } + // else { + // Settings.data = settings; + // if (Settings.data.version !== SettingsManager.DEFAULT.version) { + // const key = Settings.data.key; + // console.log('mismatched version', key); + // await Settings.reset(); + // Settings.data.key = key; + // } + // } + // resolve(); + // }); + // }); + // } + + static _get_settings() { return new Promise(resolve => { - const storage = bapi.browser.storage; - if (!storage) { - resolve(); - return; - } - storage.sync.get(['settings'], async ({settings}) => { - if (!settings) { - await Settings.reset(); - } - else { - Settings.data = settings; - if (Settings.data.version !== SettingsManager.DEFAULT.version) { - const key = Settings.data.key; - console.log('mismatched version', key); - await Settings.reset(); - Settings.data.key = key; - } - } - // // Temporary fix - // if (Settings.data.key?.startsWith('MIIBI')) { - // Settings.data.key = ''; - // } - resolve(); + bapi.browser.storage.sync.get(['settings'], ({settings}) => { + console.log('Settings._get_settings', settings); + resolve(settings); }); }); } + static async load() { + for (let i = 0; i < 4; i++) { + const settings = await Settings._get_settings(); + if (!settings) { + // await Time.sleep(100); + continue; + } + Settings.data = settings; + if (Settings.data.version !== SettingsManager.DEFAULT.version) { + const key = Settings.data.key; + console.log('mismatched version', key); + await Settings.reset(); + Settings.data.key = key; + } + return; + } + console.log('settings load retry exceeded'); + await Settings.reset(); + } + static async get() { return Settings.data; } @@ -164,14 +192,26 @@ class Settings { await Settings._save(); } + static async update({settings}) { + for (const [k, v] of Object.entries(settings)) { + Settings.data[k] = v; + } + await Settings._save(); + } + + static async replace({settings}) { + Settings.data = settings; + await Settings._save(); + } + static async reset() { Settings.data = deep_copy(SettingsManager.DEFAULT); - // Set key from manifest - const manifest = bapi.browser.runtime.getManifest(); - if (manifest.nopecha_key) { - Settings.data.key = manifest.nopecha_key; - } + // // Set key from manifest + // const manifest = bapi.browser.runtime.getManifest(); + // if (manifest.nopecha_key) { + // Settings.data.key = manifest.nopecha_key; + // } await Settings._save(); } @@ -179,6 +219,8 @@ class Settings { static { API.register(this, 'get'); API.register(this, 'set'); + API.register(this, 'update'); + API.register(this, 'replace'); API.register(this, 'reset'); } } @@ -357,7 +399,7 @@ class Server { if (key === 'undefined') { key = ''; } - const r = await fetch(`${Server.ENDPOINT}&k=${key}`); + const r = await fetch(`${Server.ENDPOINT}&key=${key}`); plan = JSON.parse(await r.text()); } catch {} Server.is_fetching_plan = false; @@ -406,7 +448,7 @@ class Relay { class Icon { - static set_icon({status}) { + static set({status}) { return new Promise(resolve => { const ba = bapi.VERSION === 'firefox' ? bapi.browser.browserAction : bapi.browser.action; if (status === 'on') { @@ -474,7 +516,7 @@ class Icon { } static { - API.register(this, 'set_icon'); + API.register(this, 'set'); } } @@ -538,7 +580,7 @@ class ContextMenu { await Settings.load(); - await Icon.set_icon({status: Settings.data.enabled ? 'on' : 'off'}); + await Icon.set({status: Settings.data.enabled ? 'on' : 'off'}); bapi.browser.runtime.onMessage.addListener((req, sender, send) => { const method = req[0]; diff --git a/content.js b/content.js index fcb56fe..300692f 100644 --- a/content.js +++ b/content.js @@ -1,5 +1,4 @@ class BG { - // static exec(method, data) { static exec() { return new Promise(resolve => { try { @@ -114,8 +113,8 @@ class NopeCHA { const data = { type: captcha_type, task: task, - v: chrome.runtime.getManifest().version, key: key, + v: chrome.runtime.getManifest().version, url: info ? info.url : window.location.href, }; if (image_urls) { @@ -131,9 +130,17 @@ class NopeCHA { data.audio_data = audio_data; } - const text = await Net.fetch(NopeCHA.INFERENCE_URL, {method: 'POST', body: JSON.stringify(data), headers: {'Content-Type': 'application/json'}}); - try { + const headers = {'Content-Type': 'application/json'}; + if (key && key !== 'undefined') { + headers.Authorization = `Bearer ${key}`; + } + const text = await Net.fetch(NopeCHA.INFERENCE_URL, { + method: 'POST', + headers: headers, + body: JSON.stringify(data), + }); + const r = JSON.parse(text); if ('error' in r) { if (r.error === NopeCHA.ERRORS.RATE_LIMITED) { @@ -158,14 +165,14 @@ class NopeCHA { return await NopeCHA.get({job_id, key}); } catch (e) { console.log('failed to parse post response', e); - break; + // break; } } return {job_id: null, data: null}; } - static async get({key, job_id}) { + static async get({job_id, key}) { const start_time = Date.now(); while (true) { @@ -175,7 +182,13 @@ class NopeCHA { } await Time.sleep(1000); - const text = await Net.fetch(`${NopeCHA.INFERENCE_URL}?id=${job_id}&key=${key}`); + const headers = {}; + if (key && key !== 'undefined') { + headers.Authorization = `Bearer ${key}`; + } + const text = await Net.fetch(`${NopeCHA.INFERENCE_URL}?id=${job_id}&key=${key}`, { + headers: headers, + }); try { const r = JSON.parse(text); if ('error' in r) { diff --git a/manifest.base.json b/manifest.base.json index 89cefdb..c8d5b83 100644 --- a/manifest.base.json +++ b/manifest.base.json @@ -1,6 +1,6 @@ { "name": "NopeCHA: CAPTCHA Solver", - "version": "0.3.2", + "version": "0.3.3", "description": "Automatically solve reCAPTCHA, hCaptcha, FunCAPTCHA, AWS WAF, and text CAPTCHA using AI.", "permissions": [ "storage", diff --git a/popup.css b/popup.css index d9acf96..f3286d4 100644 --- a/popup.css +++ b/popup.css @@ -32,6 +32,9 @@ html, body { div { display: block; } +a { + text-decoration: none; +} button, input, optgroup, select, textarea { font-family: inherit; font-size: 100%; @@ -166,6 +169,14 @@ input[type=number] { 100% {opacity: 1;} } +/* MISC */ +.clickable { + cursor: pointer !important; +} +.clickable:hover { + opacity: 0.8 !important; +} + /* APP */ #app_frame { @@ -261,9 +272,6 @@ input[type=number] { margin-left: auto; display: flex; } -.plan_value > a { - text-decoration: none; -} .plan_button { display: flex; background-color: transparent; @@ -281,13 +289,7 @@ input[type=number] { color: #0a95ff; } .plan_button.link, -.plan_button.clickable { - cursor: pointer; -} .plan_button.link:hover, -.plan_button.clickable:hover { - opacity: 0.8; -} .plan_button_label { box-sizing: border-box; font-size: 14px; @@ -319,6 +321,20 @@ input[type=number] { /* KEY */ +.key_label { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: space-between; + width: 100%; +} +.key_label > .instructions { + font-weight: normal; + line-height: 16px; + margin-left: 6px; + color: #fff; + font-size: 10px; +} .settings_text[data-settings="key"] { background: #1a2432; position: absolute; @@ -326,7 +342,13 @@ input[type=number] { transition: all ease 0.1s; z-index: 1; } -#edit_key { +/* .edit_key { + line-height: 16px; + margin-right: 6px; + color: #fff; + font-size: 10px; +} */ +.edit_icon { z-index: 2; } @@ -382,6 +404,16 @@ button.menu_item_container { width: 16px; } +/* #export { + color: rgba(255, 255, 255, 0.5); + font-size: 1.2em; + cursor: pointer; + transition: color 0.5s ease 0s, border 0.5s ease 0s; +} +#export:hover { + color: rgb(255, 255, 255); +} */ + /* TAB */ .bbflex { @@ -399,11 +431,16 @@ button.menu_item_container { } .settings_item_container { box-sizing: border-box; - margin-bottom: 16px; + margin-bottom: 8px; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 8px; box-sizing: border-box; } +.settings_item_container > a { + color: rgba(255, 255, 255, 0.5); + text-decoration: none; + transition: color 0.5s ease 0s, border 0.5s ease 0s; +} .settings_item { width: 100%; background-color: rgba(255, 255, 255, 0.08); diff --git a/popup.html b/popup.html index 81f0feb..f1e8b87 100644 --- a/popup.html +++ b/popup.html @@ -581,60 +581,25 @@ - -
-