use navigator.userAgentData when present
This commit is contained in:
parent
ffcdf47ab5
commit
f94ba2b1c8
|
@ -1,7 +1,7 @@
|
||||||
/* global browserCommands */// background.js
|
/* global browserCommands */// background.js
|
||||||
/* global msg */
|
/* global msg */
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
/* global CHROME FIREFOX URLS ignoreChromeError */// toolbox.js
|
/* global CHROME URLS ignoreChromeError */// toolbox.js
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
click: browserCommands.reload,
|
click: browserCommands.reload,
|
||||||
},
|
},
|
||||||
'editor.contextDelete': {
|
'editor.contextDelete': {
|
||||||
presentIf: () => !FIREFOX && prefs.get('editor.contextDelete'),
|
presentIf: () => CHROME && prefs.get('editor.contextDelete'),
|
||||||
title: 'editDeleteText',
|
title: 'editDeleteText',
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
contexts: ['editable'],
|
contexts: ['editable'],
|
||||||
|
@ -40,14 +40,7 @@
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// "Delete" item in context menu for browsers that don't have it
|
prefs.__defaults['editor.contextDelete'] = Boolean(CHROME);
|
||||||
if (CHROME &&
|
|
||||||
// looking at the end of UA string
|
|
||||||
/(Vivaldi|Safari)\/[\d.]+$/.test(navigator.userAgent) &&
|
|
||||||
// skip forks with Flash as those are likely to have the menu e.g. CentBrowser
|
|
||||||
!Array.from(navigator.plugins).some(p => p.name === 'Shockwave Flash')) {
|
|
||||||
prefs.__defaults['editor.contextDelete'] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const keys = Object.keys(contextMenus);
|
const keys = Object.keys(contextMenus);
|
||||||
prefs.subscribe(keys.filter(id => typeof prefs.defaults[id] === 'boolean'),
|
prefs.subscribe(keys.filter(id => typeof prefs.defaults[id] === 'boolean'),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global FIREFOX debounce */// toolbox.js
|
/* global FIREFOX WINDOWS debounce */// toolbox.js
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -418,9 +418,7 @@ async function waitForSheet({
|
||||||
window.on('mousedown', suppressFocusRingOnClick, {passive: true});
|
window.on('mousedown', suppressFocusRingOnClick, {passive: true});
|
||||||
window.on('keydown', keepFocusRingOnTabbing, {passive: true});
|
window.on('keydown', keepFocusRingOnTabbing, {passive: true});
|
||||||
|
|
||||||
if (!/^Win\d+/.test(navigator.platform)) {
|
document.documentElement.classList.toggle('non-windows', !WINDOWS);
|
||||||
document.documentElement.classList.add('non-windows');
|
|
||||||
}
|
|
||||||
// set language for a) CSS :lang pseudo and b) hyphenation
|
// set language for a) CSS :lang pseudo and b) hyphenation
|
||||||
document.documentElement.setAttribute('lang', chrome.i18n.getUILanguage());
|
document.documentElement.setAttribute('lang', chrome.i18n.getUILanguage());
|
||||||
document.on('keypress', clickDummyLinkOnEnter);
|
document.on('keypress', clickDummyLinkOnEnter);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* global API msg */// msg.js
|
/* global API msg */// msg.js
|
||||||
/* global debounce deepMerge */// toolbox.js - not used in content scripts
|
/* global MOBILE WINDOWS debounce deepMerge */// toolbox.js - not used in content scripts
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
'manage.backup.expanded': true,
|
'manage.backup.expanded': true,
|
||||||
'manage.filters.expanded': true,
|
'manage.filters.expanded': true,
|
||||||
// the new compact layout doesn't look good on Android yet
|
// the new compact layout doesn't look good on Android yet
|
||||||
'manage.newUI': !navigator.appVersion.includes('Android'),
|
'manage.newUI': chrome.tabs ? !MOBILE : false,
|
||||||
'manage.newUI.favicons': false, // show favicons for the sites in applies-to
|
'manage.newUI.favicons': false, // show favicons for the sites in applies-to
|
||||||
'manage.newUI.faviconsGray': true, // gray out favicons
|
'manage.newUI.faviconsGray': true, // gray out favicons
|
||||||
'manage.newUI.targets': 3, // max number of applies-to targets visible: 0 = none
|
'manage.newUI.targets': 3, // max number of applies-to targets visible: 0 = none
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
'editor.smartIndent': true, // 'smart' indent
|
'editor.smartIndent': true, // 'smart' indent
|
||||||
'editor.indentWithTabs': false, // smart indent with tabs
|
'editor.indentWithTabs': false, // smart indent with tabs
|
||||||
'editor.tabSize': 4, // tab width, in spaces
|
'editor.tabSize': 4, // tab width, in spaces
|
||||||
'editor.keyMap': navigator.appVersion.indexOf('Windows') > 0 ? 'sublime' : 'default',
|
'editor.keyMap': chrome.tabs && WINDOWS ? 'sublime' : 'default',
|
||||||
'editor.theme': 'default', // CSS theme
|
'editor.theme': 'default', // CSS theme
|
||||||
// CSS beautifier
|
// CSS beautifier
|
||||||
'editor.beautify': {
|
'editor.beautify': {
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
CHROME_POPUP_BORDER_BUG
|
CHROME_POPUP_BORDER_BUG
|
||||||
|
MOBILE
|
||||||
RX_META
|
RX_META
|
||||||
|
WINDOWS
|
||||||
capitalize
|
capitalize
|
||||||
closeCurrentTab
|
closeCurrentTab
|
||||||
deepEqual
|
deepEqual
|
||||||
|
@ -22,10 +24,37 @@
|
||||||
waitForTabUrl
|
waitForTabUrl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const CHROME = Boolean(chrome.app) && Number(navigator.userAgent.match(/Chrom\w+\/(\d+)|$/)[1]);
|
let {
|
||||||
const OPERA = Boolean(chrome.app) && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]);
|
CHROME = false,
|
||||||
const VIVALDI = Boolean(chrome.app) && navigator.userAgent.includes('Vivaldi');
|
OPERA = false,
|
||||||
let FIREFOX = !chrome.app && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]);
|
VIVALDI = false,
|
||||||
|
FIREFOX = false,
|
||||||
|
Windows: WINDOWS = false,
|
||||||
|
mobile: MOBILE = false,
|
||||||
|
// New Vivaldi doesn't expose itself via `brands` or UA, only via `extData` on a Tab object.
|
||||||
|
} = (() => {
|
||||||
|
const MAP = {
|
||||||
|
OPR: 'OPERA',
|
||||||
|
Chromium: 'CHROME',
|
||||||
|
'Google Chrome': 'CHROME',
|
||||||
|
};
|
||||||
|
const uaData = navigator.userAgentData || {
|
||||||
|
// Accessing `userAgent` shows a warning in devtools.
|
||||||
|
brands: navigator.userAgent.match(/\b(\w+)\/(\d+\.\d+)/g)
|
||||||
|
.map(s => s.split('/'))
|
||||||
|
.map(([brand, version]) => ({brand, version})),
|
||||||
|
mobile: navigator.userAgent.includes('Android'),
|
||||||
|
};
|
||||||
|
const res = {
|
||||||
|
mobile: uaData.mobile,
|
||||||
|
// Vivaldi bug: no `platform` in uaData
|
||||||
|
[uaData.platform || navigator.userAgent.match(/\((\S+)|$/)[1]]: true,
|
||||||
|
};
|
||||||
|
for (const {brand, version} of uaData.brands) {
|
||||||
|
res[MAP[brand] || brand.toUpperCase()] = Number(version);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
})();
|
||||||
|
|
||||||
// see PR #781
|
// see PR #781
|
||||||
const CHROME_POPUP_BORDER_BUG = CHROME >= 62 && CHROME <= 74;
|
const CHROME_POPUP_BORDER_BUG = CHROME >= 62 && CHROME <= 74;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user