allow the admin to alter the default user-agent string

This commit is contained in:
Ray Lothian 2020-08-04 10:22:18 +02:00
parent 4e4ccd589c
commit d0340982fc
4 changed files with 32 additions and 9 deletions

View file

@ -21,6 +21,7 @@ const prefs = {
parser: {}, // maps ua string to a ua object,
log: false
};
window.prefs = prefs; // access from popup
const log = (...args) => prefs.log && console.log(...args);
@ -40,11 +41,20 @@ expand.rules = {};
chrome.storage.local.get(prefs, ps => {
Object.assign(prefs, ps);
expand();
chrome.tabs.query({}, ts => {
ts.forEach(t => tabs[t.id] = t.windowId);
ua.update();
// update prefs.ua from the managed storage
chrome.storage.managed.get({
ua: ''
}, rps => {
if (!chrome.runtime.lastError && rps.ua) {
prefs.ua = rps.ua;
}
expand();
chrome.tabs.query({}, ts => {
ts.forEach(t => tabs[t.id] = t.windowId);
ua.update();
});
});
if (chrome.browserAction.setBadgeBackgroundColor) { // FF for Android
chrome.browserAction.setBadgeBackgroundColor({
color: prefs.color

View file

@ -156,7 +156,6 @@ document.addEventListener('DOMContentLoaded', () => fetch('./map.json').then(r =
document.querySelector('#os optgroup:last-of-type').appendChild(f2);
chrome.storage.local.get({
'ua': '',
'popup-browser': 'Chrome',
'popup-os': 'Windows',
'popup-sort': 'descending'
@ -165,10 +164,12 @@ document.addEventListener('DOMContentLoaded', () => fetch('./map.json').then(r =
document.getElementById('os').value = prefs['popup-os'];
document.getElementById('sort').value = prefs['popup-sort'];
const ua = prefs.ua || navigator.userAgent;
update(ua);
document.getElementById('ua').value = ua;
document.getElementById('ua').dispatchEvent(new Event('input'));
chrome.runtime.getBackgroundPage(bg => {
const ua = bg.prefs.ua || navigator.userAgent;
update(ua);
document.getElementById('ua').value = ua;
document.getElementById('ua').dispatchEvent(new Event('input'));
});
});
}));

View file

@ -28,6 +28,9 @@
"128": "data/icons/active/128.png",
"256": "data/icons/active/256.png"
},
"storage": {
"managed_schema": "schema.json"
},
"background":{
"scripts":[
"ua-parser.min.js",

9
extension/schema.json Normal file
View file

@ -0,0 +1,9 @@
{
"type": "object",
"properties": {
"ua": {
"title": "Custom User-Agent String",
"type": "string"
}
}
}