version 0.4.1

This commit is contained in:
Ray Lothian 2020-09-06 13:26:09 +02:00
parent 855d93a46b
commit 1b18a4f7a2
6 changed files with 70 additions and 31 deletions

View file

@ -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 {

View file

@ -101,3 +101,9 @@ textarea {
grid-template-columns: 1fr 1fr;
}
}
.admin {
background-color: #ffffed;
border: solid 1px #e8ec3a;
padding: 10px;
margin: 15px 0;
}

View file

@ -60,12 +60,13 @@
<h1>Sibling Hostnames</h1>
<span id="toggle-sibling-desc">Description</span>
</div>
<p for="toggle-sibling-desc" class="note hidden">A JSON array that contains one or more groups of hostnames to have a single user-agent string per group for the "Custom Mode". For all hostnames in one group, the user-agent string calculation only occurs once, and all the other members use the same calculated string. This is useful to make sure a group of connected websites only access to the same user-agent string. Press <a href="#" id="sample-3">here</a> to insert a sample JSON array.</p>
<p for="toggle-sibling-desc" class="note hidden">A JSON array that contains one or more groups of hostnames to have a single user-agent string per group. For all hostnames in one group, the user-agent string calculation only occurs once, and all the other members use the same calculated string. This is useful to make sure a group of connected websites only access to the same user-agent string. Press <a href="#" id="sample-3">here</a> to insert a sample JSON array.</p>
<textarea id="siblings" rows="5" wrap="off"></textarea>
<div class="admin">This extension supports managed storage. All the preferences can be pre-configured by <a href="https://add0n.com/useragent-switcher.html#faq20">the domain administrator</a></div>
<div id="backup">
<button id="import">Import Settings</button>
<button id="export">Export Settings</button>
<button title="to generate minified version, press Shift key while pressing this button" id="export">Export Settings</button>
</div>
<div id="tools">
<button id="help">FAQs Page (Help)</button>

View file

@ -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'), {

View file

@ -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",

View file

@ -4,6 +4,10 @@
"ua": {
"title": "Custom User-Agent String",
"type": "string"
},
"json": {
"title": "JSON String of all Preferences",
"type": "string"
}
}
}