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 uswApi */
/* global /* global
FIREFOX FIREFOX
UA
URLS URLS
activateTab activateTab
download download
@ -177,6 +178,10 @@ if (chrome.commands) {
} }
chrome.runtime.onInstalled.addListener(({reason, previousVersion}) => { 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') { if (reason === 'update') {
const [a, b, c] = (previousVersion || '').split('.'); const [a, b, c] = (previousVersion || '').split('.');
if (a <= 1 && b <= 5 && c <= 13) { // 1.5.13 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 // "Delete" item in context menu for browsers that don't have it
if (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; prefs.__defaults['editor.contextDelete'] = true;
} }

View File

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

View File

@ -1,5 +1,6 @@
/* global $ */// dom.js /* global $ */// dom.js
/* global CodeMirror */ /* global CodeMirror */
/* global UA */// toolbox.js
/* global editor */ /* global editor */
/* global prefs */ /* global prefs */
/* global t */// localization.js /* global t */// localization.js
@ -62,7 +63,7 @@
if (!extras.includes('blockComment')) { if (!extras.includes('blockComment')) {
KM.sublime['Shift-Ctrl-/'] = 'commentSelection'; KM.sublime['Shift-Ctrl-/'] = 'commentSelection';
} }
if (navigator.appVersion.includes('Windows')) { if (UA.windows) {
// 'pcDefault' keymap on Windows should have F3/Shift-F3/Ctrl-R // 'pcDefault' keymap on Windows should have F3/Shift-F3/Ctrl-R
if (!extras.includes('findNext')) KM.pcDefault['F3'] = 'findNext'; if (!extras.includes('findNext')) KM.pcDefault['F3'] = 'findNext';
if (!extras.includes('findPrev')) KM.pcDefault['Shift-F3'] = 'findPrev'; 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 */ /* global prefs */
'use strict'; 'use strict';
@ -468,9 +468,7 @@ const dom = {};
'/js/dom-on-load', '/js/dom-on-load',
]; ];
const elHtml = document.documentElement; const elHtml = document.documentElement;
if (!/^Win\d+/.test(navigator.platform)) { if (!UA.windows) elHtml.classList.add('non-windows');
elHtml.classList.add('non-windows');
}
// set language for a) CSS :lang pseudo and b) hyphenation // set language for a) CSS :lang pseudo and b) hyphenation
elHtml.setAttribute('lang', chrome.i18n.getUILanguage()); elHtml.setAttribute('lang', chrome.i18n.getUILanguage());
// set up header width resizer // set up header width resizer

View File

@ -56,7 +56,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': true,
'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
@ -71,7 +71,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': 'default',
'editor.theme': 'default', // CSS theme 'editor.theme': 'default', // CSS theme
// CSS beautifier // CSS beautifier
'editor.beautify': { 'editor.beautify': {

View File

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

View File

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

View File

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