version 0.4.1
This commit is contained in:
parent
855d93a46b
commit
1b18a4f7a2
6 changed files with 70 additions and 31 deletions
|
@ -18,21 +18,19 @@ chrome.tabs.onCreated.addListener(tab => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const prefs = {
|
const prefs = {
|
||||||
ua: '',
|
'ua': '',
|
||||||
blacklist: [],
|
'blacklist': [],
|
||||||
whitelist: [],
|
'whitelist': [],
|
||||||
custom: {},
|
'custom': {},
|
||||||
siblings: {
|
'siblings': {}, // a list of domains that are considered siblings (use same index for all)
|
||||||
'www.google.com': 0,
|
'mode': 'blacklist',
|
||||||
'www.youtube.com': 0
|
'color': '#777',
|
||||||
}, // a list of domains that are considered siblings (use same index for all)
|
'cache': true,
|
||||||
mode: 'blacklist',
|
'exactMatch': false,
|
||||||
color: '#777',
|
'protected': ['google.com/recaptcha', 'gstatic.com/recaptcha'],
|
||||||
cache: true,
|
'parser': {}, // maps ua string to a ua object,
|
||||||
exactMatch: false,
|
'log': false,
|
||||||
protected: ['google.com/recaptcha', 'gstatic.com/recaptcha'],
|
'json-guid': 'na'
|
||||||
parser: {}, // maps ua string to a ua object,
|
|
||||||
log: false
|
|
||||||
};
|
};
|
||||||
window.prefs = prefs; // access from popup
|
window.prefs = prefs; // access from popup
|
||||||
|
|
||||||
|
@ -91,11 +89,29 @@ chrome.storage.local.get(prefs, ps => {
|
||||||
// update prefs.ua from the managed storage
|
// update prefs.ua from the managed storage
|
||||||
try {
|
try {
|
||||||
chrome.storage.managed.get({
|
chrome.storage.managed.get({
|
||||||
ua: ''
|
'ua': '',
|
||||||
|
'json': ''
|
||||||
}, rps => {
|
}, rps => {
|
||||||
if (!chrome.runtime.lastError && rps.ua) {
|
if (!chrome.runtime.lastError) {
|
||||||
chrome.storage.local.set({
|
const p = {};
|
||||||
ua: rps.ua
|
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 {
|
else {
|
||||||
|
|
|
@ -101,3 +101,9 @@ textarea {
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.admin {
|
||||||
|
background-color: #ffffed;
|
||||||
|
border: solid 1px #e8ec3a;
|
||||||
|
padding: 10px;
|
||||||
|
margin: 15px 0;
|
||||||
|
}
|
||||||
|
|
|
@ -60,12 +60,13 @@
|
||||||
<h1>Sibling Hostnames</h1>
|
<h1>Sibling Hostnames</h1>
|
||||||
<span id="toggle-sibling-desc">Description</span>
|
<span id="toggle-sibling-desc">Description</span>
|
||||||
</div>
|
</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>
|
<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">
|
<div id="backup">
|
||||||
<button id="import">Import Settings</button>
|
<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>
|
||||||
<div id="tools">
|
<div id="tools">
|
||||||
<button id="help">FAQs Page (Help)</button>
|
<button id="help">FAQs Page (Help)</button>
|
||||||
|
|
|
@ -24,6 +24,7 @@ function save() {
|
||||||
catch (e) {
|
catch (e) {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
notify('Custom JSON error: ' + e.message, 5000);
|
notify('Custom JSON error: ' + e.message, 5000);
|
||||||
|
alert('Custom JSON error: ' + e.message);
|
||||||
document.getElementById('custom').value = c;
|
document.getElementById('custom').value = c;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +37,7 @@ function save() {
|
||||||
catch (e) {
|
catch (e) {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
notify('Parser JSON error: ' + e.message, 5000);
|
notify('Parser JSON error: ' + e.message, 5000);
|
||||||
|
alert('Parser JSON error: ' + e.message);
|
||||||
document.getElementById('parser').value = p;
|
document.getElementById('parser').value = p;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
@ -52,11 +54,10 @@ function save() {
|
||||||
catch (e) {
|
catch (e) {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
notify('Sibling JSON error: ' + e.message, 5000);
|
notify('Sibling JSON error: ' + e.message, 5000);
|
||||||
document.getElementById('siblings').value = c;
|
alert('Sibling JSON error: ' + e.message);
|
||||||
|
document.getElementById('siblings').value = s;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
console.log(siblings);
|
|
||||||
|
|
||||||
|
|
||||||
chrome.storage.local.set({
|
chrome.storage.local.set({
|
||||||
exactMatch: document.getElementById('exactMatch').checked,
|
exactMatch: document.getElementById('exactMatch').checked,
|
||||||
|
@ -90,10 +91,7 @@ function restore() {
|
||||||
blacklist: [],
|
blacklist: [],
|
||||||
custom: {},
|
custom: {},
|
||||||
parser: {},
|
parser: {},
|
||||||
siblings: {
|
siblings: {},
|
||||||
'www.google.com': 0,
|
|
||||||
'www.youtube.com': 0
|
|
||||||
},
|
|
||||||
protected: ['google.com/recaptcha', 'gstatic.com/recaptcha']
|
protected: ['google.com/recaptcha', 'gstatic.com/recaptcha']
|
||||||
}, prefs => {
|
}, prefs => {
|
||||||
document.getElementById('exactMatch').checked = prefs.exactMatch;
|
document.getElementById('exactMatch').checked = prefs.exactMatch;
|
||||||
|
@ -178,9 +176,23 @@ document.getElementById('help').addEventListener('click', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// export
|
// 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 => {
|
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 blob = new Blob([text], {type: 'application/json'});
|
||||||
const objectURL = URL.createObjectURL(blob);
|
const objectURL = URL.createObjectURL(blob);
|
||||||
Object.assign(document.createElement('a'), {
|
Object.assign(document.createElement('a'), {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "User-Agent Switcher and Manager",
|
"name": "User-Agent Switcher and Manager",
|
||||||
"short_name": "useragent-switcher",
|
"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",
|
"description": "Spoof websites trying to gather information about your web navigation to deliver distinct content you may not want",
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
"ua": {
|
"ua": {
|
||||||
"title": "Custom User-Agent String",
|
"title": "Custom User-Agent String",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"json": {
|
||||||
|
"title": "JSON String of all Preferences",
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue