diff --git a/.eslintrc b/.eslintrc index cee33bfa..e85b0c08 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,7 +11,6 @@ env: globals: # messaging.js KEEP_CHANNEL_OPEN: false - RX_SUPPORTED_URLS: false FIREFOX: false OPERA: false URLS: false diff --git a/edit.js b/edit.js index 7360c046..99308bd4 100644 --- a/edit.js +++ b/edit.js @@ -1666,7 +1666,6 @@ function showLintHelp() { function showRegExpTester(event, section = getSectionForChild(this)) { const GET_FAVICON_URL = 'https://www.google.com/s2/favicons?domain='; const OWN_ICON = chrome.runtime.getManifest().icons['16']; - const RX_SUPPORTED_URLS = new RegExp(`^(file|https?|ftps?):|^${URLS.ownOrigin}`); const cachedRegexps = showRegExpTester.cachedRegexps = showRegExpTester.cachedRegexps || new Map(); const regexps = [...section.querySelector('.applies-to-list').children] @@ -1696,7 +1695,7 @@ function showRegExpTester(event, section = getSectionForChild(this)) { }); chrome.tabs.query({}, tabs => { const supported = tabs.map(tab => tab.url) - .filter(url => RX_SUPPORTED_URLS.test(url)); + .filter(url => URLS.supported.test(url)); const unique = [...new Set(supported).values()]; for (const rxData of regexps) { const {rx, urls} = rxData; diff --git a/messaging.js b/messaging.js index 94c058dd..a5062b99 100644 --- a/messaging.js +++ b/messaging.js @@ -3,25 +3,31 @@ // keep message channel open for sendResponse in chrome.runtime.onMessage listener const KEEP_CHANNEL_OPEN = true; + const FIREFOX = /Firefox/.test(navigator.userAgent); const OPERA = /OPR/.test(navigator.userAgent); + const URLS = { ownOrigin: chrome.runtime.getURL(''), + optionsUI: [ chrome.runtime.getURL('options/index.html'), 'chrome://extensions/?options=' + chrome.runtime.id, ], + configureCommands: OPERA ? 'opera://settings/configureCommands' : 'chrome://extensions/configureCommands', + // CWS cannot be scripted in chromium, see ChromeExtensionsClient::IsScriptableURL // https://cs.chromium.org/chromium/src/chrome/common/extensions/chrome_extensions_client.cc chromeWebStore: FIREFOX ? 'N/A' : 'https://chrome.google.com/webstore/', + + supported: new RegExp( + '^(file|ftps?|http)://|' + + `^https://${FIREFOX ? '' : '(?!chrome\\.google\\.com/webstore)'}|` + + '^' + chrome.runtime.getURL('')), }; -const RX_SUPPORTED_URLS = new RegExp( - '^(file|ftps?|http)://|' + - `^https://${FIREFOX ? '' : '(?!chrome\\.google\\.com/webstore)'}|` + - '^' + URLS.ownOrigin); let BG = chrome.extension.getBackgroundPage(); diff --git a/popup.js b/popup.js index de54567e..813bbd62 100644 --- a/popup.js +++ b/popup.js @@ -5,7 +5,7 @@ let tabURL; const handleEvent = {}; getActiveTabRealURL().then(url => { - tabURL = RX_SUPPORTED_URLS.test(url) ? url : ''; + tabURL = URLS.supported.test(url) ? url : ''; Promise.all([ tabURL && getStylesSafe({matchUrl: tabURL}), onDOMready().then(() => {