Index: lib/elemHide.js
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -353,21 +353,24 @@
/**
* Generates a style sheet for a given domain based on the current set of
* filters.
*
* @param {string} domain The domain.
* @param {boolean} [specificOnly=false] Whether selectors from generic
* filters should be included.
+ * @param {boolean} [includeSelectors=false] Whether the return value should
+ * include a separate list of selectors.
*
* @returns {ElemHideStyleSheet} An object containing the CSS code and the
* list of selectors.
*/
- generateStyleSheetForDomain(domain, specificOnly = false)
+ generateStyleSheetForDomain(domain, specificOnly = false,
+ includeSelectors = false)
{
let code = null;
let selectors = null;
if (domain[domain.length - 1] == ".")
domain = domain.replace(/\.+$/, "");
domain = domain.toLowerCase();
@@ -376,24 +379,34 @@
{
selectors = getConditionalSelectors(domain, true);
code = createStyleSheet(selectors);
}
else
{
let knownSuffix = getKnownSuffix(domain);
- selectors = getConditionalSelectors(knownSuffix, false);
- code = knownSuffix == "" ? getCommonStyleSheet() :
- (getDefaultStyleSheet() + createStyleSheet(selectors));
+ if (includeSelectors)
+ {
+ selectors = getConditionalSelectors(knownSuffix, false);
+ code = knownSuffix == "" ? getCommonStyleSheet() :
+ (getDefaultStyleSheet() + createStyleSheet(selectors));
- selectors = getUnconditionalSelectors().concat(selectors);
+ selectors = getUnconditionalSelectors().concat(selectors);
+ }
+ else
+ {
+ code = knownSuffix == "" ? getCommonStyleSheet() :
+ (getDefaultStyleSheet() +
+ createStyleSheet(getConditionalSelectors(knownSuffix,
+ false)));
+ }
}
- return {code, selectors};
+ return {code, selectors: includeSelectors ? selectors : null};
}
};
/**
* Splits a list of selectors into groups determined by the value of
* {@link selectorGroupSize}
.
*
* @param {Array.} selectors
Index: test/elemHide.js
===================================================================
--- a/test/elemHide.js
+++ b/test/elemHide.js
@@ -53,17 +53,17 @@
});
}
function testResult(test, domain, expectedSelectors, specificOnly)
{
let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
let {code, selectors} =
- ElemHide.generateStyleSheetForDomain(domain, specificOnly);
+ ElemHide.generateStyleSheetForDomain(domain, specificOnly, true);
test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors);
// Make sure each expected selector is in the actual CSS code.
for (let selector of normalizedExpectedSelectors)
{
test.ok(code.includes(selector + ", ") ||
code.includes(selector + " {display: none !important;}\n"));