check userAgentData when available

This commit is contained in:
tophf 2022-01-27 15:21:02 +03:00
parent 8afab0eaeb
commit 60834f7bd6
9 changed files with 42 additions and 28 deletions

View File

@ -10,6 +10,7 @@
/* global uswApi */
/* global
FIREFOX
UA
URLS
activateTab
download
@ -177,6 +178,10 @@ if (chrome.commands) {
}
chrome.runtime.onInstalled.addListener(({reason, previousVersion}) => {
if (reason === 'install') {
if (UA.mobile) prefs.set('manage.newUI', false);
if (UA.windows) prefs.set('editor.keyMap', 'sublime');
}
if (reason === 'update') {
const [a, b, c] = (previousVersion || '').split('.');
if (a <= 1 && b <= 5 && c <= 13) { // 1.5.13

View File

@ -41,11 +41,7 @@
};
// "Delete" item in context menu for browsers that don't have it
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')) {
if (CHROME) {
prefs.__defaults['editor.contextDelete'] = true;
}

View File

@ -2,17 +2,17 @@
/* global addAPI bgReady */// common.js
/* global prefs */
/* global tabMan */
/* global CHROME FIREFOX VIVALDI debounce ignoreChromeError */// toolbox.js
/* global CHROME FIREFOX UA debounce ignoreChromeError */// toolbox.js
'use strict';
/* exported iconMan */
const iconMan = (() => {
const ICON_SIZES = FIREFOX || CHROME >= 55 && !VIVALDI ? [16, 32] : [19, 38];
const ICON_SIZES = FIREFOX || CHROME && !UA.vivaldi ? [16, 32] : [19, 38];
const staleBadges = new Set();
const imageDataCache = new Map();
const badgeOvr = {color: '', text: ''};
// https://github.com/openstyles/stylus/issues/1287 Fenix can't use custom ImageData
const FIREFOX_ANDROID = FIREFOX && navigator.userAgent.includes('Android');
const FIREFOX_ANDROID = FIREFOX && UA.mobile;
// https://github.com/openstyles/stylus/issues/335
let hasCanvas = FIREFOX_ANDROID ? false : loadImage(`/images/icon/${ICON_SIZES[0]}.png`)

View File

@ -1,5 +1,6 @@
/* global $ */// dom.js
/* global CodeMirror */
/* global UA */// toolbox.js
/* global editor */
/* global prefs */
/* global t */// localization.js
@ -62,7 +63,7 @@
if (!extras.includes('blockComment')) {
KM.sublime['Shift-Ctrl-/'] = 'commentSelection';
}
if (navigator.appVersion.includes('Windows')) {
if (UA.windows) {
// 'pcDefault' keymap on Windows should have F3/Shift-F3/Ctrl-R
if (!extras.includes('findNext')) KM.pcDefault['F3'] = 'findNext';
if (!extras.includes('findPrev')) KM.pcDefault['Shift-F3'] = 'findPrev';

View File

@ -1,4 +1,4 @@
/* global FIREFOX */// toolbox.js
/* global FIREFOX UA */// toolbox.js
/* global prefs */
'use strict';
@ -468,9 +468,7 @@ const dom = {};
'/js/dom-on-load',
];
const elHtml = document.documentElement;
if (!/^Win\d+/.test(navigator.platform)) {
elHtml.classList.add('non-windows');
}
if (!UA.windows) elHtml.classList.add('non-windows');
// set language for a) CSS :lang pseudo and b) hyphenation
elHtml.setAttribute('lang', chrome.i18n.getUILanguage());
// set up header width resizer

View File

@ -56,7 +56,7 @@
'manage.backup.expanded': true,
'manage.filters.expanded': true,
// the new compact layout doesn't look good on Android yet
'manage.newUI': !navigator.appVersion.includes('Android'),
'manage.newUI': true,
'manage.newUI.favicons': false, // show favicons for the sites in applies-to
'manage.newUI.faviconsGray': true, // gray out favicons
'manage.newUI.targets': 3, // max number of applies-to targets visible: 0 = none
@ -71,7 +71,7 @@
'editor.smartIndent': true, // 'smart' indent
'editor.indentWithTabs': false, // smart indent with tabs
'editor.tabSize': 4, // tab width, in spaces
'editor.keyMap': navigator.appVersion.indexOf('Windows') > 0 ? 'sublime' : 'default',
'editor.keyMap': 'default',
'editor.theme': 'default', // CSS theme
// CSS beautifier
'editor.beautify': {

View File

@ -3,6 +3,7 @@
/* exported
CHROME_POPUP_BORDER_BUG
RX_META
UA
capitalize
clamp
closeCurrentTab
@ -23,10 +24,23 @@
waitForTabUrl
*/
const CHROME = Boolean(chrome.app) && Number(navigator.userAgent.match(/Chrom\w+\/(\d+)|$/)[1]);
const OPERA = Boolean(chrome.app) && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]);
const VIVALDI = Boolean(chrome.app) && navigator.userAgent.includes('Vivaldi');
let FIREFOX = !chrome.app && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]);
let FIREFOX;
const [CHROME, UA] = (() => {
const uad = navigator.userAgentData;
const ua = uad || navigator.userAgent;
const brands = uad ? uad.brands.map(_ => `${_.brand}/${_.version}`).join(' ') : ua;
const getVer = name => Number(brands.match(new RegExp(name + '\\w*/(\\d+)|$'))[1]) || false;
FIREFOX = !chrome.app && getVer('Firefox');
return [
getVer('Chrom'),
{
mobile: uad ? uad.mobile : /Android/.test(ua),
windows: /Windows/.test(uad ? uad.platform : ua),
opera: getVer('(Opera|OPR)'),
vivaldi: getVer('Vivaldi'),
},
];
})();
// see PR #781
const CHROME_POPUP_BORDER_BUG = CHROME >= 62 && CHROME <= 74;
@ -47,7 +61,7 @@ const URLS = {
ownOrigin: chrome.runtime.getURL(''),
configureCommands:
OPERA ? 'opera://settings/configureCommands'
UA.opera ? 'opera://settings/configureCommands'
: 'chrome://extensions/configureCommands',
installUsercss: chrome.runtime.getURL('install-usercss.html'),
@ -56,7 +70,7 @@ const URLS = {
// https://cs.chromium.org/chromium/src/chrome/common/extensions/chrome_extensions_client.cc
browserWebStore:
FIREFOX ? 'https://addons.mozilla.org/' :
OPERA ? 'https://addons.opera.com/' :
UA.opera ? 'https://addons.opera.com/' :
'https://chrome.google.com/webstore/',
emptyTab: [
@ -124,11 +138,11 @@ const URLS = {
const RX_META = /\/\*!?\s*==userstyle==[\s\S]*?==\/userstyle==\s*\*\//i;
if (FIREFOX || OPERA || VIVALDI) {
if (FIREFOX || UA.opera || UA.vivaldi) {
document.documentElement.classList.add(
FIREFOX && 'firefox' ||
OPERA && 'opera' ||
VIVALDI && 'vivaldi');
UA.opera && 'opera' ||
UA.vivaldi && 'vivaldi');
}
// FF57+ supports openerTabId, but not in Android

View File

@ -1,5 +1,5 @@
/* global API msg */// msg.js
/* global CHROME VIVALDI debounce */// toolbox.js
/* global CHROME UA debounce */// toolbox.js
/* global Events handleBulkChange handleVisibilityChange */// events.js
/* global fitSelectBoxesIn switchUI showStyles */// render.js
/* global prefs */
@ -78,7 +78,7 @@ newUI.renderClass();
].map(id => `--${id}:"${CSS.escape(t(id))}";`).join('')
}}`);
if (!VIVALDI) {
if (!UA.vivaldi) {
waitForSheet().then(() => {
fitSelectBoxesIn($('#filters'));
});

View File

@ -14,7 +14,7 @@
CHROME
CHROME_POPUP_BORDER_BUG
FIREFOX
OPERA
UA
URLS
capitalize
clamp
@ -34,7 +34,7 @@ if (CHROME_POPUP_BORDER_BUG) {
}
// collapse #advanced block in Chrome pre-66 (classic chrome://extensions UI)
if (!FIREFOX && !OPERA && CHROME < 66) {
if (!FIREFOX && !UA.opera && CHROME < 66) {
const block = $('#advanced');
$('h1', block).onclick = event => {
event.preventDefault();