diff --git a/background/style-manager.js b/background/style-manager.js index a1dee182..ff18192d 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -1,5 +1,5 @@ /* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */ -/* global createCache db calcStyleDigest db tryRegExp styleCodeEmpty +/* global createCache db calcStyleDigest db tryRegExp styleCodeEmpty styleSectionGlobal getStyleWithNoCode msg sync uuidv4 */ /* exported styleManager */ 'use strict'; @@ -445,7 +445,7 @@ const styleManager = (() => { excluded = true; } for (const section of data.sections) { - if (styleCodeEmpty(section.code)) { + if (styleSectionGlobal(section) && styleCodeEmpty(section.code)) { continue; } const match = urlMatchSection(query, section); @@ -612,15 +612,7 @@ const styleManager = (() => { return 'sloppy'; } // TODO: check for invalid regexps? - if ( - (!section.regexps || !section.regexps.length) && - (!section.urlPrefixes || !section.urlPrefixes.length) && - (!section.urls || !section.urls.length) && - (!section.domains || !section.domains.length) - ) { - return true; - } - return false; + return styleSectionGlobal(section); } function createCompiler(compile) { diff --git a/js/sections-util.js b/js/sections-util.js index f44b52a2..48a2f9c1 100644 --- a/js/sections-util.js +++ b/js/sections-util.js @@ -1,4 +1,4 @@ -/* exported styleSectionsEqual styleCodeEmpty calcStyleDigest styleJSONseemsValid */ +/* exported styleSectionsEqual styleCodeEmpty styleSectionGlobal calcStyleDigest styleJSONseemsValid */ 'use strict'; function styleCodeEmpty(code) { @@ -14,6 +14,14 @@ function styleCodeEmpty(code) { return false; } +/** Checks if section is global i.e. has no targets at all */ +function styleSectionGlobal(section) { + return (!section.regexps || !section.regexps.length) && + (!section.urlPrefixes || !section.urlPrefixes.length) && + (!section.urls || !section.urls.length) && + (!section.domains || !section.domains.length); +} + /** * @param {Style} a - first style object * @param {Style} b - second style object