overwriting product, oscpu, and productSub
This commit is contained in:
parent
aa31d04c32
commit
35d216070a
2 changed files with 36 additions and 37 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* globals UAParser*/
|
/* globals UAParser */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -75,9 +75,11 @@ var ua = {
|
||||||
o.appVersion = s
|
o.appVersion = s
|
||||||
.replace(/^Mozilla\//, '')
|
.replace(/^Mozilla\//, '')
|
||||||
.replace(/^Opera\//, '');
|
.replace(/^Opera\//, '');
|
||||||
const p = new UAParser(s);
|
const p = (new UAParser(s)).getResult();
|
||||||
o.platform = p.getOS().name || '';
|
o.platform = p.os.name || '';
|
||||||
o.vendor = p.getDevice().vendor || '';
|
o.vendor = p.device.vendor || '';
|
||||||
|
o.product = p.engine.name || '';
|
||||||
|
o.oscpu = ((p.os.name || '') + ' ' + (p.os.version || '')).trim();
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
},
|
},
|
||||||
|
@ -260,9 +262,9 @@ var onCommitted = ({frameId, url, tabId}) => {
|
||||||
}
|
}
|
||||||
const o = cache[tabId] || ua.object(tabId);
|
const o = cache[tabId] || ua.object(tabId);
|
||||||
if (o.userAgent) {
|
if (o.userAgent) {
|
||||||
let {userAgent, appVersion, platform, vendor} = o;
|
let {userAgent, appVersion, platform, vendor, product, oscpu} = o;
|
||||||
if (o.userAgent === 'empty') {
|
if (o.userAgent === 'empty') {
|
||||||
userAgent = appVersion = platform = vendor = '';
|
userAgent = appVersion = platform = vendor = product = '';
|
||||||
}
|
}
|
||||||
chrome.tabs.executeScript(tabId, {
|
chrome.tabs.executeScript(tabId, {
|
||||||
runAt: 'document_start',
|
runAt: 'document_start',
|
||||||
|
@ -274,10 +276,15 @@ var onCommitted = ({frameId, url, tabId}) => {
|
||||||
const appVersion = "${encodeURIComponent(appVersion)}";
|
const appVersion = "${encodeURIComponent(appVersion)}";
|
||||||
const platform = "${encodeURIComponent(platform)}";
|
const platform = "${encodeURIComponent(platform)}";
|
||||||
const vendor = "${encodeURIComponent(vendor)}";
|
const vendor = "${encodeURIComponent(vendor)}";
|
||||||
|
const product = "${encodeURIComponent(product)}";
|
||||||
|
const oscpu = "${encodeURIComponent(oscpu)}";
|
||||||
navigator.__defineGetter__('userAgent', () => decodeURIComponent(userAgent));
|
navigator.__defineGetter__('userAgent', () => decodeURIComponent(userAgent));
|
||||||
navigator.__defineGetter__('appVersion', () => decodeURIComponent(appVersion));
|
navigator.__defineGetter__('appVersion', () => decodeURIComponent(appVersion));
|
||||||
navigator.__defineGetter__('platform', () => decodeURIComponent(platform));
|
navigator.__defineGetter__('platform', () => decodeURIComponent(platform));
|
||||||
navigator.__defineGetter__('vendor', () => decodeURIComponent(vendor));
|
navigator.__defineGetter__('vendor', () => decodeURIComponent(vendor));
|
||||||
|
navigator.__defineGetter__('product', () => decodeURIComponent(product));
|
||||||
|
navigator.__defineGetter__('oscpu', () => decodeURIComponent(oscpu));
|
||||||
|
navigator.__defineGetter__('productSub', () => '');
|
||||||
}\`;
|
}\`;
|
||||||
document.documentElement.appendChild(script);
|
document.documentElement.appendChild(script);
|
||||||
script.remove();
|
script.remove();
|
||||||
|
@ -296,36 +303,28 @@ chrome.contextMenus.onClicked.addListener(info => chrome.storage.local.set({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// FAQs & Feedback
|
// FAQs & Feedback
|
||||||
chrome.storage.local.get({
|
{
|
||||||
'version': null,
|
const {onInstalled, setUninstallURL, getManifest} = chrome.runtime;
|
||||||
'faqs': false,
|
const {name, version} = getManifest();
|
||||||
'last-update': 0
|
const page = getManifest().homepage_url;
|
||||||
}, prefs => {
|
onInstalled.addListener(({reason, previousVersion}) => {
|
||||||
const version = chrome.runtime.getManifest().version;
|
chrome.storage.local.get({
|
||||||
|
'faqs': true,
|
||||||
if (prefs.version ? (prefs.faqs && prefs.version !== version) : true) {
|
'last-update': 0
|
||||||
const now = Date.now();
|
}, prefs => {
|
||||||
const doUpdate = (now - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45;
|
if (reason === 'install' || (prefs.faqs && reason === 'update')) {
|
||||||
chrome.storage.local.set({
|
const doUpdate = (Date.now() - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45;
|
||||||
version,
|
if (doUpdate && previousVersion !== version) {
|
||||||
'last-update': doUpdate ? Date.now() : prefs['last-update']
|
chrome.tabs.create({
|
||||||
}, () => {
|
url: page + '?version=' + version +
|
||||||
// do not display the FAQs page if last-update occurred less than 45 days ago.
|
(previousVersion ? '&p=' + previousVersion : '') +
|
||||||
if (doUpdate) {
|
'&type=' + reason,
|
||||||
const p = Boolean(prefs.version);
|
active: reason === 'install'
|
||||||
chrome.tabs.create({
|
});
|
||||||
url: chrome.runtime.getManifest().homepage_url + '?version=' + version +
|
chrome.storage.local.set({'last-update': Date.now()});
|
||||||
'&type=' + (p ? ('upgrade&p=' + prefs.version) : 'install'),
|
}
|
||||||
active: p === false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
setUninstallURL(page + '?rd=feedback&name=' + encodeURIComponent(name) + '&version=' + version);
|
||||||
|
|
||||||
{
|
|
||||||
const {name, version} = chrome.runtime.getManifest();
|
|
||||||
chrome.runtime.setUninstallURL(
|
|
||||||
chrome.runtime.getManifest().homepage_url + '?rd=feedback&name=' + name + '&version=' + version
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.2.7",
|
"version": "0.2.8",
|
||||||
|
|
||||||
"description": "Spoofs User-Agent strings of your browser with a new one globally, randomly or per hostname",
|
"description": "Spoofs User-Agent strings of your browser with a new one globally, randomly or per hostname",
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue