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, parser: {}, // maps ua string to a ua object,
log: false log: false
}; };
window.prefs = prefs; // access from popup
const log = (...args) => prefs.log && console.log(...args); const log = (...args) => prefs.log && console.log(...args);
@ -40,11 +41,20 @@ expand.rules = {};
chrome.storage.local.get(prefs, ps => { chrome.storage.local.get(prefs, ps => {
Object.assign(prefs, ps); Object.assign(prefs, ps);
// update prefs.ua from the managed storage
chrome.storage.managed.get({
ua: ''
}, rps => {
if (!chrome.runtime.lastError && rps.ua) {
prefs.ua = rps.ua;
}
expand(); expand();
chrome.tabs.query({}, ts => { chrome.tabs.query({}, ts => {
ts.forEach(t => tabs[t.id] = t.windowId); ts.forEach(t => tabs[t.id] = t.windowId);
ua.update(); ua.update();
}); });
});
if (chrome.browserAction.setBadgeBackgroundColor) { // FF for Android if (chrome.browserAction.setBadgeBackgroundColor) { // FF for Android
chrome.browserAction.setBadgeBackgroundColor({ chrome.browserAction.setBadgeBackgroundColor({
color: prefs.color 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); document.querySelector('#os optgroup:last-of-type').appendChild(f2);
chrome.storage.local.get({ chrome.storage.local.get({
'ua': '',
'popup-browser': 'Chrome', 'popup-browser': 'Chrome',
'popup-os': 'Windows', 'popup-os': 'Windows',
'popup-sort': 'descending' 'popup-sort': 'descending'
@ -165,11 +164,13 @@ document.addEventListener('DOMContentLoaded', () => fetch('./map.json').then(r =
document.getElementById('os').value = prefs['popup-os']; document.getElementById('os').value = prefs['popup-os'];
document.getElementById('sort').value = prefs['popup-sort']; document.getElementById('sort').value = prefs['popup-sort'];
const ua = prefs.ua || navigator.userAgent; chrome.runtime.getBackgroundPage(bg => {
const ua = bg.prefs.ua || navigator.userAgent;
update(ua); update(ua);
document.getElementById('ua').value = ua; document.getElementById('ua').value = ua;
document.getElementById('ua').dispatchEvent(new Event('input')); document.getElementById('ua').dispatchEvent(new Event('input'));
}); });
});
})); }));
document.getElementById('list').addEventListener('click', ({target}) => { document.getElementById('list').addEventListener('click', ({target}) => {

View file

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