From 1b18a4f7a2c7fcd613b543e44142f15fb9804a38 Mon Sep 17 00:00:00 2001 From: Ray Lothian Date: Sun, 6 Sep 2020 13:26:09 +0200 Subject: [PATCH] version 0.4.1 --- extension/common.js | 54 ++++++++++++++++++++----------- extension/data/options/index.css | 6 ++++ extension/data/options/index.html | 5 +-- extension/data/options/index.js | 30 +++++++++++------ extension/manifest.json | 2 +- extension/schema.json | 4 +++ 6 files changed, 70 insertions(+), 31 deletions(-) diff --git a/extension/common.js b/extension/common.js index 98b3e4c..2f56a73 100644 --- a/extension/common.js +++ b/extension/common.js @@ -18,21 +18,19 @@ chrome.tabs.onCreated.addListener(tab => { }); const prefs = { - ua: '', - blacklist: [], - whitelist: [], - custom: {}, - siblings: { - 'www.google.com': 0, - 'www.youtube.com': 0 - }, // a list of domains that are considered siblings (use same index for all) - mode: 'blacklist', - color: '#777', - cache: true, - exactMatch: false, - protected: ['google.com/recaptcha', 'gstatic.com/recaptcha'], - parser: {}, // maps ua string to a ua object, - log: false + 'ua': '', + 'blacklist': [], + 'whitelist': [], + 'custom': {}, + 'siblings': {}, // a list of domains that are considered siblings (use same index for all) + 'mode': 'blacklist', + 'color': '#777', + 'cache': true, + 'exactMatch': false, + 'protected': ['google.com/recaptcha', 'gstatic.com/recaptcha'], + 'parser': {}, // maps ua string to a ua object, + 'log': false, + 'json-guid': 'na' }; window.prefs = prefs; // access from popup @@ -91,11 +89,29 @@ chrome.storage.local.get(prefs, ps => { // update prefs.ua from the managed storage try { chrome.storage.managed.get({ - ua: '' + 'ua': '', + 'json': '' }, rps => { - if (!chrome.runtime.lastError && rps.ua) { - chrome.storage.local.set({ - ua: rps.ua + if (!chrome.runtime.lastError) { + const p = {}; + if (rps.json) { + try { + const j = JSON.parse(rps.json); + if (prefs['json-guid'] !== j['json-guid'] || j['json-forced']) { + Object.assign(p, j); + console.warn('preferences are updated by an admin'); + } + } + catch (e) { + console.warn('cannot parse remote JSON', e); + } + } + if (rps.ua) { + p.ua = rps.ua; + console.warn('user-agent string is updated by an admin'); + } + chrome.storage.local.set(p, () => { + ua.update(undefined, undefined, DCSI); }); } else { diff --git a/extension/data/options/index.css b/extension/data/options/index.css index f4d56ce..890d673 100644 --- a/extension/data/options/index.css +++ b/extension/data/options/index.css @@ -101,3 +101,9 @@ textarea { grid-template-columns: 1fr 1fr; } } +.admin { + background-color: #ffffed; + border: solid 1px #e8ec3a; + padding: 10px; + margin: 15px 0; +} diff --git a/extension/data/options/index.html b/extension/data/options/index.html index 436290f..e327e13 100644 --- a/extension/data/options/index.html +++ b/extension/data/options/index.html @@ -60,12 +60,13 @@

Sibling Hostnames

Description - + +
This extension supports managed storage. All the preferences can be pre-configured by the domain administrator
- +
diff --git a/extension/data/options/index.js b/extension/data/options/index.js index 5ac02c9..3ee487c 100644 --- a/extension/data/options/index.js +++ b/extension/data/options/index.js @@ -24,6 +24,7 @@ function save() { catch (e) { window.setTimeout(() => { notify('Custom JSON error: ' + e.message, 5000); + alert('Custom JSON error: ' + e.message); document.getElementById('custom').value = c; }, 1000); } @@ -36,6 +37,7 @@ function save() { catch (e) { window.setTimeout(() => { notify('Parser JSON error: ' + e.message, 5000); + alert('Parser JSON error: ' + e.message); document.getElementById('parser').value = p; }, 1000); } @@ -52,11 +54,10 @@ function save() { catch (e) { window.setTimeout(() => { notify('Sibling JSON error: ' + e.message, 5000); - document.getElementById('siblings').value = c; + alert('Sibling JSON error: ' + e.message); + document.getElementById('siblings').value = s; }, 1000); } - console.log(siblings); - chrome.storage.local.set({ exactMatch: document.getElementById('exactMatch').checked, @@ -90,10 +91,7 @@ function restore() { blacklist: [], custom: {}, parser: {}, - siblings: { - 'www.google.com': 0, - 'www.youtube.com': 0 - }, + siblings: {}, protected: ['google.com/recaptcha', 'gstatic.com/recaptcha'] }, prefs => { document.getElementById('exactMatch').checked = prefs.exactMatch; @@ -178,9 +176,23 @@ document.getElementById('help').addEventListener('click', () => { }); // export -document.getElementById('export').addEventListener('click', () => { +document.getElementById('export').addEventListener('click', e => { + const guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { + const r = Math.random() * 16 | 0; + const v = c == 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); + chrome.storage.local.get(null, prefs => { - const text = JSON.stringify(prefs, null, ' '); + for (const key of Object.keys(prefs)) { + if (key && key.startsWith('cache.')) { + delete prefs[key]; + } + } + const text = JSON.stringify(Object.assign({}, prefs, { + 'json-guid': guid, + 'json-forced': false + }), null, e.shiftKey ? '' : ' '); const blob = new Blob([text], {type: 'application/json'}); const objectURL = URL.createObjectURL(blob); Object.assign(document.createElement('a'), { diff --git a/extension/manifest.json b/extension/manifest.json index 24e5ac3..791e8b7 100755 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "User-Agent Switcher and Manager", "short_name": "useragent-switcher", - "version": "0.4.0.2", + "version": "0.4.1", "description": "Spoof websites trying to gather information about your web navigation to deliver distinct content you may not want", diff --git a/extension/schema.json b/extension/schema.json index 7a6a1da..96b767d 100644 --- a/extension/schema.json +++ b/extension/schema.json @@ -4,6 +4,10 @@ "ua": { "title": "Custom User-Agent String", "type": "string" + }, + "json": { + "title": "JSON String of all Preferences", + "type": "string" } } }