code cosmetics: RX_SUPPORTED_URLS -> URLS.supported

This commit is contained in:
tophf 2017-04-17 22:43:59 +03:00
parent 021f50015b
commit 3b3ed6543e
4 changed files with 12 additions and 8 deletions

View File

@ -11,7 +11,6 @@ env:
globals: globals:
# messaging.js # messaging.js
KEEP_CHANNEL_OPEN: false KEEP_CHANNEL_OPEN: false
RX_SUPPORTED_URLS: false
FIREFOX: false FIREFOX: false
OPERA: false OPERA: false
URLS: false URLS: false

View File

@ -1666,7 +1666,6 @@ function showLintHelp() {
function showRegExpTester(event, section = getSectionForChild(this)) { function showRegExpTester(event, section = getSectionForChild(this)) {
const GET_FAVICON_URL = 'https://www.google.com/s2/favicons?domain='; const GET_FAVICON_URL = 'https://www.google.com/s2/favicons?domain=';
const OWN_ICON = chrome.runtime.getManifest().icons['16']; const OWN_ICON = chrome.runtime.getManifest().icons['16'];
const RX_SUPPORTED_URLS = new RegExp(`^(file|https?|ftps?):|^${URLS.ownOrigin}`);
const cachedRegexps = showRegExpTester.cachedRegexps = const cachedRegexps = showRegExpTester.cachedRegexps =
showRegExpTester.cachedRegexps || new Map(); showRegExpTester.cachedRegexps || new Map();
const regexps = [...section.querySelector('.applies-to-list').children] const regexps = [...section.querySelector('.applies-to-list').children]
@ -1696,7 +1695,7 @@ function showRegExpTester(event, section = getSectionForChild(this)) {
}); });
chrome.tabs.query({}, tabs => { chrome.tabs.query({}, tabs => {
const supported = tabs.map(tab => tab.url) 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()]; const unique = [...new Set(supported).values()];
for (const rxData of regexps) { for (const rxData of regexps) {
const {rx, urls} = rxData; const {rx, urls} = rxData;

View File

@ -3,25 +3,31 @@
// keep message channel open for sendResponse in chrome.runtime.onMessage listener // keep message channel open for sendResponse in chrome.runtime.onMessage listener
const KEEP_CHANNEL_OPEN = true; const KEEP_CHANNEL_OPEN = true;
const FIREFOX = /Firefox/.test(navigator.userAgent); const FIREFOX = /Firefox/.test(navigator.userAgent);
const OPERA = /OPR/.test(navigator.userAgent); const OPERA = /OPR/.test(navigator.userAgent);
const URLS = { const URLS = {
ownOrigin: chrome.runtime.getURL(''), ownOrigin: chrome.runtime.getURL(''),
optionsUI: [ optionsUI: [
chrome.runtime.getURL('options/index.html'), chrome.runtime.getURL('options/index.html'),
'chrome://extensions/?options=' + chrome.runtime.id, 'chrome://extensions/?options=' + chrome.runtime.id,
], ],
configureCommands: configureCommands:
OPERA ? 'opera://settings/configureCommands' OPERA ? 'opera://settings/configureCommands'
: 'chrome://extensions/configureCommands', : 'chrome://extensions/configureCommands',
// CWS cannot be scripted in chromium, see ChromeExtensionsClient::IsScriptableURL // CWS cannot be scripted in chromium, see ChromeExtensionsClient::IsScriptableURL
// 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
chromeWebStore: FIREFOX ? 'N/A' : 'https://chrome.google.com/webstore/', chromeWebStore: FIREFOX ? 'N/A' : 'https://chrome.google.com/webstore/',
};
const RX_SUPPORTED_URLS = new RegExp( supported: new RegExp(
'^(file|ftps?|http)://|' + '^(file|ftps?|http)://|' +
`^https://${FIREFOX ? '' : '(?!chrome\\.google\\.com/webstore)'}|` + `^https://${FIREFOX ? '' : '(?!chrome\\.google\\.com/webstore)'}|` +
'^' + URLS.ownOrigin); '^' + chrome.runtime.getURL('')),
};
let BG = chrome.extension.getBackgroundPage(); let BG = chrome.extension.getBackgroundPage();

View File

@ -5,7 +5,7 @@ let tabURL;
const handleEvent = {}; const handleEvent = {};
getActiveTabRealURL().then(url => { getActiveTabRealURL().then(url => {
tabURL = RX_SUPPORTED_URLS.test(url) ? url : ''; tabURL = URLS.supported.test(url) ? url : '';
Promise.all([ Promise.all([
tabURL && getStylesSafe({matchUrl: tabURL}), tabURL && getStylesSafe({matchUrl: tabURL}),
onDOMready().then(() => { onDOMready().then(() => {