From bf4e42f808ef2959c7e8afadcc531c8be0a7f828 Mon Sep 17 00:00:00 2001 From: erosman Date: Mon, 20 Nov 2023 15:35:53 +0330 Subject: [PATCH] Add files via upload --- src/content/migrate.js | 2 +- src/content/options.js | 24 ++++++++++++++++++++---- src/content/proxy.js | 6 +++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/content/migrate.js b/src/content/migrate.js index bdb12c0..e4f4873 100644 --- a/src/content/migrate.js +++ b/src/content/migrate.js @@ -132,7 +132,7 @@ export class Migrate { }; // Validate RegExp, deactivate on error - !Pattern.validate(p.pattern, p.type) && (p.active = false); + !Pattern.validate(pat.pattern, pat.type) && (pat.active = false); // whitelist: Inclusive/Exclusive p.whitelist === 'Inclusive' ? pxy.include.push(pat) : pxy.exclude.push(pat); diff --git a/src/content/options.js b/src/content/options.js index c617e51..910cec4 100644 --- a/src/content/options.js +++ b/src/content/options.js @@ -89,6 +89,7 @@ class Options { const arr = passthrough.split(/[\s,;]+/) .map(i => /[\d.]+\/\d+/.test(i) ? i : i.replace(/(?<=[a-z\d])\/[^\s,;]*/gi, ''));// remove path this.passthrough.value = [...new Set(arr)].join(separator); // remove duplicates + pref.passthrough = this.passthrough.value; // --- check and build proxies & patterns const data = []; @@ -511,13 +512,13 @@ class Proxies { }); pac.addEventListener('change', e => { - const {hostname, port} = App.parseURL(e.target.value); - if (!hostname) { + const {hostname: h, port: p} = App.parseURL(e.target.value); + if (!h) { e.target.classList.add('invalid'); return; } - hostname.value = hostname; - port && (port.value = port); + hostname.value = h; + p && (port.value = p); }); // patterns @@ -944,6 +945,21 @@ class ImportProxyList { pram[key.toLowerCase()] = value; } + // fix missing default port + if (!pram.port) { + switch (type) { + case 'http': + case 'ws': + pram.port = '80'; + break; + + case 'https': + case 'wss': + pram.port = '443'; + break; + } + } + // proxy template const pxy = { active: pram.active !== 'false', // defaults to true diff --git a/src/content/proxy.js b/src/content/proxy.js index ae2191a..f0e279e 100644 --- a/src/content/proxy.js +++ b/src/content/proxy.js @@ -64,7 +64,7 @@ export class Proxy { if (!control) { browser.action.setTitle({title: browser.i18n.getMessage('controlledByOtherExtensions')}); - browser.action.setBadgeText({text: '❌'}); + browser.action.setBadgeText({text: ''}); return null; } @@ -284,7 +284,7 @@ String.raw`function FindProxyForURL(url, host) { // Chrome commands returns command, tab static async excludeHost(pref, tab) { - const activeTab = tab || await this.getActiveTab(); + const activeTab = tab ? [tab] : await this.getActiveTab(); const url = this.getURL(activeTab[0].url); if (!url) { return; } @@ -302,7 +302,7 @@ String.raw`function FindProxyForURL(url, host) { this.set(pref); // update Proxy } - static async getActiveTab() { + static getActiveTab() { return browser.tabs.query({currentWindow: true, active: true}); }