From 94ed435e751fdfc1e1376ae6a2e80b6703a28c6e Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 14 Nov 2017 10:52:54 +0300 Subject: [PATCH] fixup d2b9b302: prevent setting version var to 'undefined' --- .eslintrc | 1 + background/style-via-api.js | 2 +- js/messaging.js | 13 ++++++------- js/prefs.js | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0d107f4a..b72d8204 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,6 +11,7 @@ env: globals: # messaging.js KEEP_CHANNEL_OPEN: false + CHROME: false FIREFOX: false OPERA: false URLS: false diff --git a/background/style-via-api.js b/background/style-via-api.js index e7736a2b..664a1ecb 100644 --- a/background/style-via-api.js +++ b/background/style-via-api.js @@ -1,7 +1,7 @@ /* global getStyles */ 'use strict'; -const styleViaAPI = !chrome.app && (() => { +const styleViaAPI = !CHROME && (() => { const ACTIONS = { styleApply, styleDeleted, diff --git a/js/messaging.js b/js/messaging.js index 1098a9eb..c16a149f 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -5,10 +5,11 @@ // keep message channel open for sendResponse in chrome.runtime.onMessage listener const KEEP_CHANNEL_OPEN = true; -let FIREFOX = !chrome.app && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]); -const OPERA = chrome.app && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]); +const CHROME = Boolean(chrome.app) && parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]); +const OPERA = CHROME && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]); +let FIREFOX = !CHROME && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]); -if (!chrome.app && !chrome.browserAction.openPopup) { +if (!CHROME && !chrome.browserAction.openPopup) { // in FF pre-57 legacy addons can override useragent so we assume the worst // until we know for sure in the async getBrowserInfo() // (browserAction.openPopup was added in 57) @@ -39,9 +40,7 @@ const URLS = { // Chrome 61.0.3161+ doesn't run content scripts on NTP https://crrev.com/2978953002/ // TODO: remove when "minimum_chrome_version": "61" or higher - chromeProtectsNTP: - chrome.app && - parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]) >= 3161, + chromeProtectsNTP: CHROME >= 3161, supported: url => ( url.startsWith('http') && !url.startsWith(URLS.browserWebStore) || @@ -64,7 +63,7 @@ if (!BG || BG !== window) { document.documentElement.classList.toggle('opera', OPERA); // TODO: remove once our manifest's minimum_chrome_version is 50+ // Chrome 49 doesn't report own extension pages in webNavigation apparently - if (chrome.app && navigator.userAgent.includes('Chrome/49.')) { + if (CHROME && CHROME < 2661) { getActiveTab().then(BG.updateIcon); } } diff --git a/js/prefs.js b/js/prefs.js index 79f75d2f..0b576b77 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -320,7 +320,7 @@ var prefs = new function Prefs() { } function contextDeleteMissing() { - return chrome.app && ( + return CHROME && ( // detect browsers without Delete by looking at the end of UA string /Vivaldi\/[\d.]+$/.test(navigator.userAgent) || // Chrome and co.