diff --git a/.eslintrc b/.eslintrc index 04989f20..2e335468 100644 --- a/.eslintrc +++ b/.eslintrc @@ -82,7 +82,7 @@ rules: dot-location: [2, property] dot-notation: [0] eol-last: [2] - eqeqeq: [0] + eqeqeq: [1, always] func-call-spacing: [2, never] func-name-matching: [0] func-names: [0] diff --git a/background/background.js b/background/background.js index fc5a7f30..3b4f1aa7 100644 --- a/background/background.js +++ b/background/background.js @@ -33,7 +33,7 @@ chrome.tabs.onAttached.addListener((tabId, data) => { if (tab.url.startsWith(URLS.ownOrigin + 'edit.html')) { chrome.windows.get(tab.windowId, {populate: true}, win => { // If there's only one tab in this window, it's been dragged to new window - prefs.set('openEditInWindow', win.tabs.length == 1); + prefs.set('openEditInWindow', win.tabs.length === 1); }); } }); @@ -59,13 +59,13 @@ updateIcon({id: undefined}, {}); const manifest = chrome.runtime.getManifest(); // Open FAQs page once after installation to guide new users. // Do not display it in development mode. - if (reason == 'install' && manifest.update_url) { + if (reason === 'install' && manifest.update_url) { setTimeout(openURL, 100, { url: 'http://add0n.com/stylus.html' }); } // reset L10N cache on update - if (reason == 'update') { + if (reason === 'update') { localStorage.L10N = JSON.stringify({ browserUIlanguage: chrome.i18n.getUILanguage(), }); @@ -138,7 +138,7 @@ contextMenus = Object.assign({ const item = Object.assign({id}, contextMenus[id]); const prefValue = prefs.readOnlyValues[id]; item.title = chrome.i18n.getMessage(item.title); - if (!item.type && typeof prefValue == 'boolean') { + if (!item.type && typeof prefValue === 'boolean') { item.type = 'checkbox'; item.checked = prefValue; } @@ -151,7 +151,7 @@ contextMenus = Object.assign({ }; createContextMenus(); prefs.subscribe((id, checked) => { - if (id == 'editor.contextDelete') { + if (id === 'editor.contextDelete') { if (checked) { createContextMenus([id]); } else { @@ -160,7 +160,7 @@ contextMenus = Object.assign({ } else { chrome.contextMenus.update(id, {checked}, ignoreChromeError); } - }, Object.keys(contextMenus).filter(key => typeof prefs.readOnlyValues[key] == 'boolean')); + }, Object.keys(contextMenus).filter(key => typeof prefs.readOnlyValues[key] === 'boolean')); } // ************************************************************************* @@ -176,7 +176,7 @@ contextMenus = Object.assign({ .replace(/\*/g, '.*?'), flags); for (const cs of contentScripts) { cs.matches = cs.matches.map(m => ( - m == ALL_URLS ? m : wildcardAsRegExp(m) + m === ALL_URLS ? m : wildcardAsRegExp(m) )); } @@ -191,8 +191,8 @@ contextMenus = Object.assign({ const pingCS = (cs, {id, url}) => { cs.matches.some(match => { - if ((match == ALL_URLS || url.match(match)) - && (!url.startsWith('chrome') || url == NTP)) { + if ((match === ALL_URLS || url.match(match)) + && (!url.startsWith('chrome') || url === NTP)) { chrome.tabs.sendMessage(id, PING, pong => { if (!pong) { injectCS(cs, id); @@ -229,7 +229,7 @@ function webNavigationListener(method, {url, tabId, frameId}) { }); } // main page frame id is 0 - if (frameId == 0) { + if (frameId === 0) { updateIcon({id: tabId, url}, styles); } }); @@ -258,7 +258,7 @@ function updateIcon(tab, styles) { } } const disableAll = 'disableAll' in styles ? styles.disableAll : prefs.get('disableAll'); - const postfix = disableAll ? 'x' : numStyles == 0 ? 'w' : ''; + const postfix = disableAll ? 'x' : numStyles === 0 ? 'w' : ''; const color = prefs.get(disableAll ? 'badgeDisabled' : 'badgeNormal'); const text = prefs.get('show-badge') && numStyles ? String(numStyles) : ''; const iconset = ['', 'light/'][prefs.get('iconset')] || ''; diff --git a/background/storage.js b/background/storage.js index 00b4f392..7531f0fb 100644 --- a/background/storage.js +++ b/background/storage.js @@ -63,7 +63,7 @@ function dbExec(method, data) { reject(event); }, onupgradeneeded(event) { - if (event.oldVersion == 0) { + if (event.oldVersion === 0) { event.target.result.createObjectStore('styles', { keyPath: 'id', autoIncrement: true, @@ -111,15 +111,17 @@ function filterStyles({ asHash = null, strictRegexp = true, // used by the popup to detect bad regexps } = {}) { - enabled = enabled === null || typeof enabled == 'boolean' ? enabled : - typeof enabled == 'string' ? enabled == 'true' : null; + enabled = enabled === null || typeof enabled === 'boolean' ? enabled : + typeof enabled === 'string' ? enabled === 'true' : null; id = id === null ? null : Number(id); - if (enabled === null - && url === null - && id === null - && matchUrl === null - && asHash != true) { + if ( + enabled === null && + url === null && + id === null && + matchUrl === null && + asHash !== true + ) { return cachedStyles.list; } const blankHash = asHash && { @@ -191,9 +193,9 @@ function filterStylesInternal({ let style; for (let i = 0; (style = styles[i]); i++) { - if ((enabled === null || style.enabled == enabled) - && (url === null || style.url == url) - && (id === null || style.id == id)) { + if ((enabled === null || style.enabled === enabled) + && (url === null || style.url === url) + && (id === null || style.id === id)) { const sections = needSections && getApplicableSections({style, matchUrl, strictRegexp, stopOnFirst: !asHash}); if (asHash) { @@ -233,16 +235,16 @@ function saveStyle(style) { } let existed; let codeIsUpdated; - if (reason == 'update' || reason == 'update-digest') { + if (reason === 'update' || reason === 'update-digest') { return calcStyleDigest(style).then(digest => { style.originalDigest = digest; return decide(); }); } - if (reason == 'import') { + if (reason === 'import') { style.originalDigest = style.originalDigest || style.styleDigest; // TODO: remove in the future delete style.styleDigest; // TODO: remove in the future - if (typeof style.originalDigest != 'string' || style.originalDigest.length != 40) { + if (typeof style.originalDigest !== 'string' || style.originalDigest.length !== 40) { delete style.originalDigest; } } @@ -255,7 +257,7 @@ function saveStyle(style) { return dbExec('get', id).then((event, store) => { const oldStyle = event.target.result; existed = Boolean(oldStyle); - if (reason == 'update-digest' && oldStyle.originalDigest == style.originalDigest) { + if (reason === 'update-digest' && oldStyle.originalDigest === style.originalDigest) { return style; } codeIsUpdated = !existed || 'sections' in style && !styleSectionsEqual(style, oldStyle); @@ -289,7 +291,7 @@ function saveStyle(style) { } function done(event) { - if (reason == 'update-digest') { + if (reason === 'update-digest') { return style; } style.id = style.id || event.target.result; @@ -367,14 +369,14 @@ function getApplicableSections({style, matchUrl, strictRegexp = true, stopOnFirs function arraySomeMatches(array, matchUrl, strictRegexp) { for (const regexp of array) { for (let pass = 1; pass <= (strictRegexp ? 1 : 2); pass++) { - const cacheKey = pass == 1 ? regexp : SLOPPY_REGEXP_PREFIX + regexp; + const cacheKey = pass === 1 ? regexp : SLOPPY_REGEXP_PREFIX + regexp; let rx = cachedStyles.regexps.get(cacheKey); - if (rx == false) { + if (rx === false) { // invalid regexp break; } if (!rx) { - const anchored = pass == 1 ? '^(?:' + regexp + ')$' : '^' + regexp + '$'; + const anchored = pass === 1 ? '^(?:' + regexp + ')$' : '^' + regexp + '$'; rx = tryRegExp(anchored); cachedStyles.regexps.set(cacheKey, rx || false); if (!rx) { @@ -415,7 +417,7 @@ function styleSectionsEqual({sections: a}, {sections: b}) { if (!a || !b) { return undefined; } - if (a.length != b.length) { + if (a.length !== b.length) { return false; } const checkedInB = []; @@ -432,16 +434,16 @@ function styleSectionsEqual({sections: a}, {sections: b}) { return false; } } - return equalOrEmpty(secA.code, secB.code, 'substr', (a, b) => a == b); + return equalOrEmpty(secA.code, secB.code, 'substr', (a, b) => a === b); } function equalOrEmpty(a, b, telltale, comparator) { - const typeA = a && typeof a[telltale] == 'function'; - const typeB = b && typeof b[telltale] == 'function'; + const typeA = a && typeof a[telltale] === 'function'; + const typeB = b && typeof b[telltale] === 'function'; return ( (a === null || a === undefined || (typeA && !a.length)) && (b === null || b === undefined || (typeB && !b.length)) - ) || typeA && typeB && a.length == b.length && comparator(a, b); + ) || typeA && typeB && a.length === b.length && comparator(a, b); } function arrayMirrors(array1, array2) { @@ -525,12 +527,12 @@ function cleanupCachedFilters({force = false} = {}) { function getDomains(url) { - if (url.indexOf('file:') == 0) { + if (url.indexOf('file:') === 0) { return []; } let d = /.*?:\/*([^/:]+)/.exec(url)[1]; const domains = [d]; - while (d.indexOf('.') != -1) { + while (d.indexOf('.') !== -1) { d = d.substring(d.indexOf('.') + 1); domains.push(d); } diff --git a/background/update.js b/background/update.js index a536098c..04f368f5 100644 --- a/background/update.js +++ b/background/update.js @@ -68,17 +68,17 @@ var updater = { }); function maybeFetchMd5(digest) { - if (!ignoreDigest && style.originalDigest && style.originalDigest != digest) { + if (!ignoreDigest && style.originalDigest && style.originalDigest !== digest) { return Promise.reject(updater.EDITED); } return download(style.md5Url); } function maybeFetchCode(md5) { - if (!md5 || md5.length != 32) { + if (!md5 || md5.length !== 32) { return Promise.reject(updater.ERROR_MD5); } - if (md5 == style.originalMd5 && style.originalDigest && !ignoreDigest) { + if (md5 === style.originalMd5 && style.originalDigest && !ignoreDigest) { return Promise.reject(updater.SAME_MD5); } return download(style.updateUrl); @@ -109,8 +109,8 @@ var updater = { return json && json.sections && json.sections.length - && typeof json.sections.every == 'function' - && typeof json.sections[0].code == 'string'; + && typeof json.sections.every === 'function' + && typeof json.sections[0].code === 'string'; } }, diff --git a/content/apply.js b/content/apply.js index 6e310f05..0cb626e0 100644 --- a/content/apply.js +++ b/content/apply.js @@ -28,7 +28,7 @@ function requestStyles(options, callback = applyStyles) { // dynamic about: and javascript: iframes don't have an URL yet // so we'll try the parent frame which is guaranteed to have a real URL try { - if (window != parent) { + if (window !== parent) { matchUrl = parent.location.href; } } catch (e) {} @@ -49,7 +49,7 @@ function requestStyles(options, callback = applyStyles) { function applyOnMessage(request, sender, sendResponse) { - if (request.styles == 'DIY') { + if (request.styles === 'DIY') { // Do-It-Yourself tells our built-in pages to fetch the styles directly // which is faster because IPC messaging JSON-ifies everything internally requestStyles({}, styles => { @@ -114,7 +114,7 @@ function doDisableAll(disable = disableAll) { disableAll = disable; Array.prototype.forEach.call(document.styleSheets, stylesheet => { if (stylesheet.ownerNode.matches(`STYLE.stylus[id^="${ID_PREFIX}"]`) - && stylesheet.disabled != disable) { + && stylesheet.disabled !== disable) { stylesheet.disabled = disable; } }); @@ -122,14 +122,14 @@ function doDisableAll(disable = disableAll) { function doExposeIframes(state = exposeIframes) { - if (state === exposeIframes || window == parent) { + if (state === exposeIframes || window === parent) { return; } exposeIframes = state; const attr = document.documentElement.getAttribute('stylus-iframe'); - if (state && attr != '') { + if (state && attr !== '') { document.documentElement.setAttribute('stylus-iframe', ''); - } else if (!state && attr == '') { + } else if (!state && attr === '') { document.documentElement.removeAttribute('stylus-iframe'); } } @@ -193,7 +193,7 @@ function applyStyles(styles) { } if (document.head && document.head.firstChild - && document.head.firstChild.id == 'xml-viewer-style') { + && document.head.firstChild.id === 'xml-viewer-style') { // when site response is application/xml Chrome displays our style elements // under document.documentElement as plain text so we need to move them into HEAD // which is already autogenerated at this moment @@ -293,7 +293,7 @@ function initDocRewriteObserver() { for (let m = mutations.length; --m >= 0;) { const added = mutations[m].addedNodes; for (let n = added.length; --n >= 0;) { - if (added[n].localName == 'html') { + if (added[n].localName === 'html') { reinjectStyles(); return; } @@ -303,7 +303,7 @@ function initDocRewriteObserver() { docRewriteObserver.observe(document, {childList: true}); // detect dynamic iframes rewritten after creation by the embedder i.e. externally setTimeout(() => { - if (document.documentElement != ROOT) { + if (document.documentElement !== ROOT) { reinjectStyles(); } }); diff --git a/content/install.js b/content/install.js index 89600266..0445af7f 100644 --- a/content/install.js +++ b/content/install.js @@ -15,7 +15,7 @@ document.addEventListener('stylishInstallOpera', onInstallClicked); chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { // orphaned content script check - if (msg.method == 'ping') { + if (msg.method === 'ping') { sendResponse(true); } }); @@ -32,7 +32,7 @@ document.documentElement.appendChild(document.createElement('script')).text = '( Response.prototype.json = function (...args) { return originalResponseJson.call(this, ...args).then(json => { Response.prototype.json = originalResponseJson; - if (!settings || typeof ((json || {}).style_settings || {}).every != 'function') { + if (!settings || typeof ((json || {}).style_settings || {}).every !== 'function') { return json; } const images = new Map(); @@ -46,18 +46,18 @@ document.documentElement.appendChild(document.createElement('script')).text = '( if (value.startsWith('ik-')) { value = value.replace(/^ik-/, ''); const defaultItem = jsonSetting.style_setting_options.find(item => item.default); - if (!defaultItem || defaultItem.install_key != value) { + if (!defaultItem || defaultItem.install_key !== value) { if (defaultItem) { defaultItem.default = false; } jsonSetting.style_setting_options.some(item => { - if (item.install_key == value) { + if (item.install_key === value) { item.default = true; return true; } }); } - } else if (jsonSetting.setting_type == 'image') { + } else if (jsonSetting.setting_type === 'image') { jsonSetting.style_setting_options.some(item => { if (item.default) { item.default = false; @@ -67,7 +67,7 @@ document.documentElement.appendChild(document.createElement('script')).text = '( images.set(jsonSetting.install_key, value); } else { const item = jsonSetting.style_setting_options[0]; - if (item.value !== value && item.install_key == 'placeholder') { + if (item.value !== value && item.install_key === 'placeholder') { item.value = value; } } @@ -151,7 +151,7 @@ function checkUpdatability([installedStyle]) { const md5Url = getMeta('stylish-md5-url'); if (md5Url && installedStyle.md5Url && installedStyle.originalMd5) { getResource(md5Url).then(md5 => { - reportUpdatable(md5 != installedStyle.originalMd5); + reportUpdatable(md5 !== installedStyle.originalMd5); }); } else { getResource(getStyleURL()).then(code => { @@ -180,7 +180,7 @@ function sendEvent(type, detail = null) { type = type.replace('Chrome', 'Opera'); } detail = {detail}; - if (typeof cloneInto != 'undefined') { + if (typeof cloneInto !== 'undefined') { // Firefox requires explicit cloning, however USO can't process our messages anyway // because USO tries to use a global "event" variable deprecated in Firefox detail = cloneInto(detail, document); // eslint-disable-line no-undef @@ -227,7 +227,7 @@ function saveStyleCode(message, name, addProps) { reason: 'update', }), style => { - if (message == 'styleUpdate' && style.updateUrl.includes('?')) { + if (message === 'styleUpdate' && style.updateUrl.includes('?')) { enableUpdateButton(true); } else { sendEvent('styleInstalledChrome'); @@ -269,7 +269,7 @@ function styleSectionsEqual({sections: a}, {sections: b}) { if (!a || !b) { return undefined; } - if (a.length != b.length) { + if (a.length !== b.length) { return false; } const checkedInB = []; @@ -286,16 +286,16 @@ function styleSectionsEqual({sections: a}, {sections: b}) { return false; } } - return equalOrEmpty(secA.code, secB.code, 'substr', (a, b) => a == b); + return equalOrEmpty(secA.code, secB.code, 'substr', (a, b) => a === b); } function equalOrEmpty(a, b, telltale, comparator) { - const typeA = a && typeof a[telltale] == 'function'; - const typeB = b && typeof b[telltale] == 'function'; + const typeA = a && typeof a[telltale] === 'function'; + const typeB = b && typeof b[telltale] === 'function'; return ( (a === null || a === undefined || (typeA && !a.length)) && (b === null || b === undefined || (typeB && !b.length)) - ) || typeA && typeB && a.length == b.length && comparator(a, b); + ) || typeA && typeB && a.length === b.length && comparator(a, b); } function arrayMirrors(array1, array2) { @@ -315,7 +315,7 @@ function styleSectionsEqual({sections: a}, {sections: b}) { function onDOMready() { - if (document.readyState != 'loading') { + if (document.readyState !== 'loading') { return Promise.resolve(); } return new Promise(resolve => { diff --git a/edit/edit.js b/edit/edit.js index f8e63006..8afb891e 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -45,7 +45,7 @@ Object.defineProperty(Array.prototype, 'last', {get: function () { return this[t new MutationObserver((mutations, observer) => { const themeElement = document.getElementById('cm-theme'); if (themeElement) { - themeElement.href = prefs.get('editor.theme') == 'default' ? '' + themeElement.href = prefs.get('editor.theme') === 'default' ? '' : 'vendor/codemirror/theme/' + prefs.get('editor.theme') + '.css'; observer.disconnect(); } @@ -68,8 +68,8 @@ const hotkeyRerouter = { eventHandler: event => { const keyName = CodeMirror.keyName(event); if ( - CodeMirror.lookupKey(keyName, CodeMirror.getOption('keyMap'), handleCommand) == 'handled' || - CodeMirror.lookupKey(keyName, CodeMirror.defaults.extraKeys, handleCommand) == 'handled' + CodeMirror.lookupKey(keyName, CodeMirror.getOption('keyMap'), handleCommand) === 'handled' || + CodeMirror.lookupKey(keyName, CodeMirror.defaults.extraKeys, handleCommand) === 'handled' ) { event.preventDefault(); event.stopPropagation(); @@ -90,7 +90,7 @@ function onChange(event) { setCleanItem(node, node.savedValue === currentValue); } else { // the manually added section's applies-to is dirty only when the value is non-empty - setCleanItem(node, node.localName != 'input' || !node.value.trim()); + setCleanItem(node, node.localName !== 'input' || !node.value.trim()); delete node.savedValue; // only valid when actually saved } updateTitle(); @@ -122,7 +122,7 @@ function setCleanItem(node, isClean) { } function isCleanGlobal() { - const clean = Object.keys(dirty).length == 0; + const clean = Object.keys(dirty).length === 0; setDirtyClass(document.body, !clean); // let saveBtn = document.getElementById('save-button') // if (clean){ @@ -270,7 +270,7 @@ function initCodeMirror() { } else { // Chrome is starting up and shows our edit.html, but the background page isn't loaded yet const theme = prefs.get('editor.theme'); - themeControl.innerHTML = optionsHtmlFromArray([theme == 'default' ? t('defaultTheme') : theme]); + themeControl.innerHTML = optionsHtmlFromArray([theme === 'default' ? t('defaultTheme') : theme]); getCodeMirrorThemes().then(() => { const themes = (localStorage.codeMirrorThemes || '').split(/\s+/); themeControl.innerHTML = optionsHtmlFromArray(themes); @@ -292,7 +292,7 @@ function acmeEventListener(event) { console.error('acmeEventListener: no "cm_option" %O', el); return; } - let value = el.type == 'checkbox' ? el.checked : el.value; + let value = el.type === 'checkbox' ? el.checked : el.value; switch (option) { case 'tabSize': CodeMirror.setOption('indentUnit', Number(value)); @@ -300,9 +300,9 @@ function acmeEventListener(event) { case 'theme': { const themeLink = document.getElementById('cm-theme'); // use non-localized 'default' internally - if (!value || value == 'default' || value == t('defaultTheme')) { + if (!value || value === 'default' || value === t('defaultTheme')) { value = 'default'; - if (prefs.get(el.id) != value) { + if (prefs.get(el.id) !== value) { prefs.set(el.id, value); } themeLink.href = ''; @@ -310,7 +310,7 @@ function acmeEventListener(event) { break; } const url = chrome.runtime.getURL('vendor/codemirror/theme/' + value + '.css'); - if (themeLink.href == url) { // preloaded in initCodeMirror() + if (themeLink.href === url) { // preloaded in initCodeMirror() break; } // avoid flicker: wait for the second stylesheet to load, then apply the theme @@ -337,7 +337,7 @@ function acmeEventListener(event) { case 'token': case 'selection': document.body.dataset[option] = value; - value = {showToken: value == 'token' && /[#.\-\w]/, annotateScrollbar: true}; + value = {showToken: value === 'token' && /[#.\-\w]/, annotateScrollbar: true}; break; default: value = null; @@ -372,7 +372,7 @@ function setupCodeMirror(textarea, index) { let lastClickTime = 0; const resizeGrip = wrapper.appendChild(template.resizeGrip.cloneNode(true)); resizeGrip.onmousedown = event => { - if (event.button != 0) { + if (event.button !== 0) { return; } event.preventDefault(); @@ -390,7 +390,7 @@ function setupCodeMirror(textarea, index) { function resize(e) { const cmPageY = wrapper.getBoundingClientRect().top + window.scrollY; const height = Math.max(minHeight, e.pageY - cmPageY); - if (height != wrapper.clientHeight) { + if (height !== wrapper.clientHeight) { cm.setSize(null, height); } } @@ -449,7 +449,7 @@ queryTabs({currentWindow: true}).then(tabs => { // window was reopened via Ctrl-Shift-T etc. chrome.windows.update(windowId, prefs.get('windowPosition')); } - if (tabs.length == 1 && window.history.length == 1) { + if (tabs.length === 1 && window.history.length === 1) { chrome.windows.getAll(windows => { if (windows.length > 1) { sessionStorageHash('saveSizeOnClose').set(windowId, true); @@ -462,14 +462,14 @@ queryTabs({currentWindow: true}).then(tabs => { } chrome.tabs.onRemoved.addListener((tabId, info) => { sessionStorageHash('manageStylesHistory').unset(tabId); - if (info.windowId == windowId && info.isWindowClosing) { + if (info.windowId === windowId && info.isWindowClosing) { sessionStorageHash('saveSizeOnClose').unset(windowId); } }); }); getActiveTab().then(tab => { - useHistoryBack = sessionStorageHash('manageStylesHistory').value[tab.id] == location.href; + useHistoryBack = sessionStorageHash('manageStylesHistory').value[tab.id] === location.href; }); function goBackToManage(event) { @@ -483,10 +483,10 @@ function goBackToManage(event) { } function isWindowMaximized() { - return window.screenLeft == 0 && - window.screenTop == 0 && - window.outerWidth == screen.availWidth && - window.outerHeight == screen.availHeight; + return window.screenLeft === 0 && + window.screenTop === 0 && + window.outerWidth === screen.availWidth && + window.outerHeight === screen.availHeight; } window.onbeforeunload = () => { @@ -568,13 +568,13 @@ function addSection(event, section) { function toggleTestRegExpVisibility() { const show = [...appliesTo.children].some(item => !item.matches('.applies-to-everything') && - item.querySelector('.applies-type').value == 'regexp' && + item.querySelector('.applies-type').value === 'regexp' && item.querySelector('.applies-value').value.trim()); div.classList.toggle('has-regexp', show); appliesTo.oninput = appliesTo.oninput || show && (event => { if ( event.target.matches('.applies-value') && - event.target.parentElement.querySelector('.applies-type').value == 'regexp' + event.target.parentElement.querySelector('.applies-type').value === 'regexp' ) { showRegExpTester(null, div); } @@ -666,7 +666,7 @@ function setupGlobalSearch() { let curState; // cm.state.search for last used 'find' function shouldIgnoreCase(query) { // treat all-lowercase non-regexp queries as case-insensitive - return typeof query == 'string' && query == query.toLowerCase(); + return typeof query === 'string' && query === query.toLowerCase(); } function updateState(cm, newState) { @@ -701,7 +701,7 @@ function setupGlobalSearch() { function focusClosestCM(activeCM) { editors.lastActive = activeCM; const cm = getEditorInSight(); - if (cm != activeCM) { + if (cm !== activeCM) { cm.focus(); } return cm; @@ -712,16 +712,16 @@ function setupGlobalSearch() { customizeOpenDialog(activeCM, template.find, function (query) { this(query); curState = activeCM.state.search; - if (editors.length == 1 || !curState.query) { + if (editors.length === 1 || !curState.query) { return; } editors.forEach(cm => { - if (cm != activeCM) { + if (cm !== activeCM) { cm.execCommand('clearSearch'); updateState(cm, curState); } }); - if (CodeMirror.cmpPos(curState.posFrom, curState.posTo) == 0) { + if (CodeMirror.cmpPos(curState.posFrom, curState.posTo) === 0) { findNext(activeCM); } }); @@ -737,12 +737,12 @@ function setupGlobalSearch() { let pos = activeCM.getCursor(reverse ? 'from' : 'to'); activeCM.setSelection(activeCM.getCursor()); // clear the selection, don't move the cursor - const rxQuery = typeof state.query == 'object' + const rxQuery = typeof state.query === 'object' ? state.query : stringAsRegExp(state.query, shouldIgnoreCase(state.query) ? 'i' : ''); if ( document.activeElement && - document.activeElement.name == 'applies-value' && + document.activeElement.name === 'applies-value' && searchAppliesTo(activeCM) ) { return; @@ -864,7 +864,7 @@ function setupGlobalSearch() { wrapAround |= cmp <= 0; const dlg = cm.getWrapperElement().querySelector('.CodeMirror-dialog'); - if (!dlg || cmp == 0 || wrapAround && CodeMirror.cmpPos(cm.getCursor(), origPos) >= 0) { + if (!dlg || cmp === 0 || wrapAround && CodeMirror.cmpPos(cm.getCursor(), origPos) >= 0) { if (dlg) { dlg.remove(); } @@ -1006,7 +1006,7 @@ function getEditorInSight(nearbyElement) { } function updateLintReport(cm, delay) { - if (delay == 0) { + if (delay === 0) { // immediately show pending csslint messages in onbeforeunload and save update(cm); return; @@ -1024,7 +1024,7 @@ function updateLintReport(cm, delay) { // or update it as soon as possible (default: 500ms lint + 100ms) in case an existing issue was just fixed clearTimeout(state.reportTimeout); state.reportTimeout = setTimeout(update, state.options.delay + 100, cm); - state.postponeNewIssues = delay == undefined || delay === null; + state.postponeNewIssues = delay === undefined || delay === null; function update(cm) { const scope = cm ? [cm] : editors; @@ -1034,16 +1034,16 @@ function updateLintReport(cm, delay) { const scopedState = cm.state.lint || {}; const oldMarkers = scopedState.markedLast || {}; const newMarkers = {}; - const html = !scopedState.marked || scopedState.marked.length == 0 ? '' : '
' + + const html = !scopedState.marked || scopedState.marked.length === 0 ? '' : '' + scopedState.marked.map(mark => { const info = mark.__annotation; - const isActiveLine = info.from.line == cm.getCursor().line; + const isActiveLine = info.from.line === cm.getCursor().line; const pos = isActiveLine ? 'cursor' : (info.from.line + ',' + info.from.ch); let message = escapeHtml(info.message.replace(/ at line \d.+$/, '')); if (message.length > 100) { message = message.substr(0, 100) + '...'; } - if (isActiveLine || oldMarkers[pos] == message) { + if (isActiveLine || oldMarkers[pos] === message) { delete oldMarkers[pos]; } newMarkers[pos] = message; @@ -1057,7 +1057,7 @@ function updateLintReport(cm, delay) { }).join('') + ''; scopedState.markedLast = newMarkers; fixedOldIssues |= scopedState.reportDisplayed && Object.keys(oldMarkers).length > 0; - if (scopedState.html != html) { + if (scopedState.html !== html) { scopedState.html = html; changed = true; } @@ -1094,12 +1094,12 @@ function renderLintReport(someBlockChanged) { issueCount += newBlock.rows.length; const block = content.children[newContent.children.length - 1]; - const blockChanged = !block || cm != block.cm || html != block.innerHTML; + const blockChanged = !block || cm !== block.cm || html !== block.innerHTML; someBlockChanged |= blockChanged; cm.state.lint.reportDisplayed = blockChanged; } }); - if (someBlockChanged || newContent.children.length != content.children.length) { + if (someBlockChanged || newContent.children.length !== content.children.length) { document.getElementById('issue-count').textContent = issueCount; container.replaceChild(newContent, content); container.style.display = newContent.children.length ? 'block' : 'none'; @@ -1112,7 +1112,7 @@ function resizeLintReport(event, content) { if (content.children.length) { const bounds = content.getBoundingClientRect(); const newMaxHeight = bounds.bottom <= innerHeight ? '' : (innerHeight - bounds.top) + 'px'; - if (newMaxHeight != content.style.maxHeight) { + if (newMaxHeight !== content.style.maxHeight) { content.style.maxHeight = newMaxHeight; } } @@ -1167,7 +1167,7 @@ function beautify(event) { ''); const undoButton = document.querySelector('#help-popup button[role="undo"]'); - undoButton.textContent = t(scope.length == 1 ? 'undo' : 'undoGlobal'); + undoButton.textContent = t(scope.length === 1 ? 'undo' : 'undoGlobal'); undoButton.addEventListener('click', () => { let undoable = false; scope.forEach(cm => { @@ -1188,7 +1188,7 @@ function beautify(event) { [Object.assign({}, r.anchor), Object.assign({}, r.head)])); const text = cm.getValue(); const newText = exports.css_beautify(text, options); - if (newText != text) { + if (newText !== text) { if (!cm.beautifyChange || !cm.beautifyChange[cm.changeGeneration()]) { // clear the list if last change wasn't a css-beautify cm.beautifyChange = {}; @@ -1206,7 +1206,7 @@ function beautify(event) { }); document.querySelector('.beautify-options').onchange = ({target}) => { - const value = target.type == 'checkbox' ? target.checked : target.selectedIndex > 0; + const value = target.type === 'checkbox' ? target.checked : target.selectedIndex > 0; prefs.set('editor.beautify', Object.assign(options, {[target.dataset.option]: value})); if (target.parentNode.hasAttribute('newline')) { target.parentNode.setAttribute('newline', value.toString()); @@ -1264,7 +1264,7 @@ function init() { window.onload = null; initWithStyle({style}); }; - if (document.readyState != 'loading') { + if (document.readyState !== 'loading') { window.onload(); } }); @@ -1346,10 +1346,10 @@ function initHooks() { function toggleContextMenuDelete(event) { - if (event.button == 2 && prefs.get('editor.contextDelete')) { + if (event.button === 2 && prefs.get('editor.contextDelete')) { chrome.contextMenus.update('editor.contextDelete', { enabled: Boolean( - this.selectionStart != this.selectionEnd || + this.selectionStart !== this.selectionEnd || this.somethingSelected && this.somethingSelected() ), }, ignoreChromeError); @@ -1412,20 +1412,20 @@ function updateTitle() { function validate() { const name = document.getElementById('name').value; - if (name == '') { + if (name === '') { return t('styleMissingName'); } // validate the regexps if (document.querySelectorAll('.applies-to-list').some(list => { list.childNodes.some(li => { - if (li.className == template.appliesToEverything.className) { + if (li.className === template.appliesToEverything.className) { return false; } const valueElement = li.querySelector('[name=applies-value]'); const type = li.querySelector('[name=applies-type]').value; const value = valueElement.value; if (type && value) { - if (type == 'regexp') { + if (type === 'regexp') { try { new RegExp(value); } catch (ex) { @@ -1472,7 +1472,7 @@ function getSectionsHashes() { getSections().forEach(div => { const meta = getMeta(div); const code = div.CodeMirror.getValue(); - if (/^\s*$/.test(code) && Object.keys(meta).length == 0) { + if (/^\s*$/.test(code) && Object.keys(meta).length === 0) { return; } meta.code = code; @@ -1484,7 +1484,7 @@ function getSectionsHashes() { function getMeta(e) { const meta = {urls: [], urlPrefixes: [], domains: [], regexps: []}; e.querySelector('.applies-to-list').childNodes.forEach(li => { - if (li.className == template.appliesToEverything.className) { + if (li.className === template.appliesToEverything.className) { return; } const type = li.querySelector('[name=applies-type]').value; @@ -1502,7 +1502,7 @@ function saveComplete(style) { setCleanGlobal(); // Go from new style URL to edit style URL - if (location.href.indexOf('id=') == -1) { + if (location.href.indexOf('id=') === -1) { history.replaceState({}, document.title, 'edit.html?id=' + style.id); tE('heading', 'editStyleHeading', null, false); } @@ -1551,7 +1551,7 @@ function fromMozillaFormat() { }); function doImport() { - const replaceOldStyle = this.name == 'import-replace'; + const replaceOldStyle = this.name === 'import-replace'; popup.querySelector('.dismiss').onclick(); const mozStyle = trimNewLines(popup.codebox.getValue()); const parser = new parserlib.css.Parser(); @@ -1578,7 +1578,7 @@ function fromMozillaFormat() { e.functions.forEach(f => { const m = f.match(/^(url|url-prefix|domain|regexp)\((['"]?)(.+?)\2?\)$/); const aType = CssToProperty[m[1]]; - const aValue = aType != 'regexps' ? m[3] : m[3].replace(/\\\\/g, '\\'); + const aValue = aType !== 'regexps' ? m[3] : m[3].replace(/\\\\/g, '\\'); (section[aType] = section[aType] || []).push(aValue); }); sectionStack.push(section); @@ -1600,7 +1600,7 @@ function fromMozillaFormat() { delete maximizeCodeHeight.stats; editors.forEach(cm => { - maximizeCodeHeight(cm.getSection(), cm == editors.last); + maximizeCodeHeight(cm.getSection(), cm === editors.last); }); makeSectionVisible(firstAddedCM); @@ -1622,7 +1622,7 @@ function fromMozillaFormat() { const C1 = start.col - 1; const L2 = end.line - 1; const C2 = end.col - 1; - if (L1 == L2) { + if (L1 === L2) { return lines[L1].substr(C1, C2 - C1 + 1); } else { const middle = lines.slice(L1 + 1, L2).join('\n'); @@ -1673,7 +1673,7 @@ function fromMozillaFormat() { function backtrackTo(parser, tokenType, startEnd) { const tokens = parser._tokenStream._lt; for (let i = parser._tokenStream._ltIndex - 1; i >= 0; --i) { - if (tokens[i].type == tokenType) { + if (tokens[i].type === tokenType) { return {line: tokens[i][startEnd + 'Line'], col: tokens[i][startEnd + 'Col']}; } } @@ -1704,7 +1704,7 @@ function showKeyMapHelp() { const keyMapSorted = Object.keys(keyMap) .map(key => ({key: key, cmd: keyMap[key]})) .concat([{key: 'Shift-Ctrl-Wheel', cmd: 'scrollWindow'}]) - .sort((a, b) => (a.cmd < b.cmd || (a.cmd == b.cmd && a.key < b.key) ? -1 : 1)); + .sort((a, b) => (a.cmd < b.cmd || (a.cmd === b.cmd && a.key < b.key) ? -1 : 1)); showHelp(t('cm_keyMap') + ': ' + prefs.get('editor.keyMap'), '' + @@ -1724,7 +1724,7 @@ function showKeyMapHelp() { function hotkeyHandler(event) { const keyName = CodeMirror.keyName(event); - if (keyName == 'Esc' || keyName == 'Tab' || keyName == 'Shift-Tab') { + if (keyName === 'Esc' || keyName === 'Tab' || keyName === 'Shift-Tab') { return; } event.preventDefault(); @@ -1754,14 +1754,14 @@ function showKeyMapHelp() { } function mergeKeyMaps(merged, ...more) { more.forEach(keyMap => { - if (typeof keyMap == 'string') { + if (typeof keyMap === 'string') { keyMap = CodeMirror.keyMap[keyMap]; } Object.keys(keyMap).forEach(key => { let cmd = keyMap[key]; // filter out '...', 'attach', etc. (hotkeys start with an uppercase letter) - if (!merged[key] && !key.match(/^[a-z]/) && cmd != '...') { - if (typeof cmd == 'function') { + if (!merged[key] && !key.match(/^[a-z]/) && cmd !== '...') { + if (typeof cmd === 'function') { // for 'emacs' keymap: provide at least something meaningful (hotkeys and the function body) // for 'vim*' keymaps: almost nothing as it doesn't rely on CM keymap mechanism cmd = cmd.toString().replace(/^function.*?\{[\s\r\n]*([\s\S]+?)[\s\r\n]*\}$/, '$1'); @@ -1795,7 +1795,7 @@ function showRegExpTester(event, section = getSectionForChild(this)) { const regexps = [...section.querySelector('.applies-to-list').children] .map(item => !item.matches('.applies-to-everything') && - item.querySelector('.applies-type').value == 'regexp' && + item.querySelector('.applies-type').value === 'regexp' && item.querySelector('.applies-value').value.trim()) .filter(item => item) .map(text => { @@ -1857,7 +1857,7 @@ function showRegExpTester(event, section = getSectionForChild(this)) { ? OWN_ICON : GET_FAVICON_URL + new URL(url).hostname; const icon = ``; - if (match.length == url.length) { + if (match.length === url.length) { full.push(` |
---|