From ecd5f1b7b7ac665b8b100a8afc080d79a238e107 Mon Sep 17 00:00:00 2001 From: Ray Lothian Date: Tue, 25 Jun 2019 08:43:08 +0100 Subject: [PATCH] fixes #38 --- extension/common.js | 6 +++++- extension/data/options/index.html | 21 +++++++++++++++------ extension/data/options/index.js | 11 +++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/extension/common.js b/extension/common.js index 960f3c9..9003de2 100644 --- a/extension/common.js +++ b/extension/common.js @@ -15,7 +15,8 @@ var prefs = { mode: 'blacklist', color: '#ffa643', cache: true, - exactMatch: false + exactMatch: false, + protected: ['google.com/recaptcha', 'gstatic.com/recaptcha'] }; chrome.storage.local.get(prefs, ps => { Object.assign(prefs, ps); @@ -256,6 +257,9 @@ var onBeforeSendHeaders = ({tabId, url, requestHeaders, type}) => { if (cache[tabId] === true) { return; } + if (prefs.protected.some(s => url.indexOf(s) !== -1)) { + return {}; + } const str = (cache[tabId] || ua.object(tabId)).userAgent; if (str) { for (let i = 0, name = requestHeaders[0].name; i < requestHeaders.length; i += 1, name = requestHeaders[i].name) { diff --git a/extension/data/options/index.html b/extension/data/options/index.html index a44bee5..64bfd8b 100644 --- a/extension/data/options/index.html +++ b/extension/data/options/index.html @@ -13,6 +13,9 @@ text-decoration: underline; text-decoration-style: dashed; } + .spacer { + padding-bottom: 10px; + } @@ -24,7 +27,7 @@ - + @@ -32,7 +35,7 @@ - + @@ -40,16 +43,22 @@ - + - + - + - + + + + A comma-separated list of keywords that the extension should not spoof the user-agent header. Use this list to protect URLs that contain these protected keywords. Each keyword need to be at least 5 char long. + + +

diff --git a/extension/data/options/index.js b/extension/data/options/index.js index 9838838..379e11e 100644 --- a/extension/data/options/index.js +++ b/extension/data/options/index.js @@ -10,9 +10,9 @@ function notify(msg, period = 750) { function prepare(str) { return str.split(/\s*,\s*/) - .map(s => s.replace('http://', '') + .map(s => s.replace('http://', '') .replace('https://', '').split('/')[0].trim()) - .filter((h, i, l) => h && l.indexOf(h) === i); + .filter((h, i, l) => h && l.indexOf(h) === i); } function save() { @@ -35,7 +35,8 @@ function save() { blacklist: prepare(document.getElementById('blacklist').value), whitelist: prepare(document.getElementById('whitelist').value), custom, - mode: document.querySelector('[name="mode"]:checked').value + mode: document.querySelector('[name="mode"]:checked').value, + protected: document.getElementById('protected').value.split(/\s*,\s*/).filter(s => s.length > 4) }, () => { restore(); notify('Options saved.'); @@ -50,7 +51,8 @@ function restore() { mode: 'blacklist', whitelist: [], blacklist: [], - custom: {} + custom: {}, + protected: ['google.com/recaptcha', 'gstatic.com/recaptcha'] }, prefs => { document.getElementById('exactMatch').checked = prefs.exactMatch; document.getElementById('faqs').checked = prefs.faqs; @@ -59,6 +61,7 @@ function restore() { document.getElementById('blacklist').value = prefs.blacklist.join(', '); document.getElementById('whitelist').value = prefs.whitelist.join(', '); document.getElementById('custom').value = JSON.stringify(prefs.custom, null, 2); + document.getElementById('protected').value = prefs.protected.join(', '); }); } document.addEventListener('DOMContentLoaded', restore);