ignore empty code only in global (non-targeted) sections

This commit is contained in:
tophf 2020-10-04 13:42:06 +03:00
parent 7c89f7b21d
commit cb89be8682
2 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */ /* 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 */ getStyleWithNoCode msg sync uuidv4 */
/* exported styleManager */ /* exported styleManager */
'use strict'; 'use strict';
@ -445,7 +445,7 @@ const styleManager = (() => {
excluded = true; excluded = true;
} }
for (const section of data.sections) { for (const section of data.sections) {
if (styleCodeEmpty(section.code)) { if (styleSectionGlobal(section) && styleCodeEmpty(section.code)) {
continue; continue;
} }
const match = urlMatchSection(query, section); const match = urlMatchSection(query, section);
@ -612,15 +612,7 @@ const styleManager = (() => {
return 'sloppy'; return 'sloppy';
} }
// TODO: check for invalid regexps? // TODO: check for invalid regexps?
if ( return styleSectionGlobal(section);
(!section.regexps || !section.regexps.length) &&
(!section.urlPrefixes || !section.urlPrefixes.length) &&
(!section.urls || !section.urls.length) &&
(!section.domains || !section.domains.length)
) {
return true;
}
return false;
} }
function createCompiler(compile) { function createCompiler(compile) {

View File

@ -1,4 +1,4 @@
/* exported styleSectionsEqual styleCodeEmpty calcStyleDigest styleJSONseemsValid */ /* exported styleSectionsEqual styleCodeEmpty styleSectionGlobal calcStyleDigest styleJSONseemsValid */
'use strict'; 'use strict';
function styleCodeEmpty(code) { function styleCodeEmpty(code) {
@ -14,6 +14,14 @@ function styleCodeEmpty(code) {
return false; 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} a - first style object
* @param {Style} b - second style object * @param {Style} b - second style object