allow the admin to alter the default user-agent string
This commit is contained in:
parent
4e4ccd589c
commit
d0340982fc
4 changed files with 32 additions and 9 deletions
|
@ -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);
|
||||
// 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
|
||||
|
|
|
@ -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,11 +164,13 @@ 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;
|
||||
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'));
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
document.getElementById('list').addEventListener('click', ({target}) => {
|
||||
|
|
|
@ -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
9
extension/schema.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ua": {
|
||||
"title": "Custom User-Agent String",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue