overwriting product, oscpu, and productSub
This commit is contained in:
parent
aa31d04c32
commit
35d216070a
2 changed files with 36 additions and 37 deletions
|
@ -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
|
||||||
|
{
|
||||||
|
const {onInstalled, setUninstallURL, getManifest} = chrome.runtime;
|
||||||
|
const {name, version} = getManifest();
|
||||||
|
const page = getManifest().homepage_url;
|
||||||
|
onInstalled.addListener(({reason, previousVersion}) => {
|
||||||
chrome.storage.local.get({
|
chrome.storage.local.get({
|
||||||
'version': null,
|
'faqs': true,
|
||||||
'faqs': false,
|
|
||||||
'last-update': 0
|
'last-update': 0
|
||||||
}, prefs => {
|
}, prefs => {
|
||||||
const version = chrome.runtime.getManifest().version;
|
if (reason === 'install' || (prefs.faqs && reason === 'update')) {
|
||||||
|
const doUpdate = (Date.now() - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45;
|
||||||
if (prefs.version ? (prefs.faqs && prefs.version !== version) : true) {
|
if (doUpdate && previousVersion !== version) {
|
||||||
const now = Date.now();
|
|
||||||
const doUpdate = (now - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45;
|
|
||||||
chrome.storage.local.set({
|
|
||||||
version,
|
|
||||||
'last-update': doUpdate ? Date.now() : prefs['last-update']
|
|
||||||
}, () => {
|
|
||||||
// do not display the FAQs page if last-update occurred less than 45 days ago.
|
|
||||||
if (doUpdate) {
|
|
||||||
const p = Boolean(prefs.version);
|
|
||||||
chrome.tabs.create({
|
chrome.tabs.create({
|
||||||
url: chrome.runtime.getManifest().homepage_url + '?version=' + version +
|
url: page + '?version=' + version +
|
||||||
'&type=' + (p ? ('upgrade&p=' + prefs.version) : 'install'),
|
(previousVersion ? '&p=' + previousVersion : '') +
|
||||||
active: p === false
|
'&type=' + reason,
|
||||||
|
active: reason === 'install'
|
||||||
});
|
});
|
||||||
|
chrome.storage.local.set({'last-update': Date.now()});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
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