Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/filterComposer.js

Issue 5358312170192896: Issue 2076 - Only generate element hiding filters if there are no blocking filters (Closed)
Patch Set: Created March 2, 2015, 4:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterComposer.js
===================================================================
--- a/lib/filterComposer.js
+++ b/lib/filterComposer.js
@@ -55,11 +55,6 @@
}
exports.quoteCSS = quoteCSS;
-function canBlockURL(url)
-{
- return url.protocol == "http:" || url.protocol == "https:";
-}
-
/**
* Generates filters to block an element.
*
@@ -82,7 +77,7 @@
for (let url of urls)
{
let urlObj = new URL(url, baseURL);
- if (canBlockURL(urlObj))
+ if (urlObj.protocol == "http:" || urlObj.protocol == "https:")
{
let filter = stringifyURL(urlObj).replace(/^[\w\-]+:\/+(?:www\.)?/, "||");
@@ -91,30 +86,34 @@
}
}
- // Generate CSS selectors based on the element's "id" and "class" attribute
+ // If we couldn't generate any blocking filters, fallback to element hiding
let selectors = [];
- if (id)
- selectors.push("#" + escapeCSS(id));
- if (classes.length > 0)
- selectors.push(classes.map(c => "." + escapeCSS(c)).join(""));
+ if (filters.length == 0)
+ {
+ // Generate CSS selectors based on the element's "id" and "class" attribute
+ if (id)
+ selectors.push("#" + escapeCSS(id));
+ if (classes.length > 0)
+ selectors.push(classes.map(c => "." + escapeCSS(c)).join(""));
- // If there is a "src" attribute, specifiying a URL that we can't block,
- // generate a CSS selector matching the "src" attribute
- if (src && !canBlockURL(new URL(src, baseURL)))
- selectors.push(escapeCSS(tagName) + "[src=" + quoteCSS(src) + "]");
+ // If there is a "src" attribute, specifiying a URL that we can't block,
+ // generate a CSS selector matching the "src" attribute
+ if (src)
+ selectors.push(escapeCSS(tagName) + "[src=" + quoteCSS(src) + "]");
- // As last resort, if there is a "style" attribute, and we couldn't generate
- // any filters so far, generate a CSS selector matching the "style" attribute
- if (style && selectors.length == 0 && filters.length == 0)
- selectors.push(escapeCSS(tagName) + "[style=" + quoteCSS(style) + "]");
+ // As last resort, if there is a "style" attribute, and we couldn't generate
+ // any filters so far, generate a CSS selector matching the "style" attribute
+ if (style && selectors.length == 0 && filters.length == 0)
+ selectors.push(escapeCSS(tagName) + "[style=" + quoteCSS(style) + "]");
- // Add an element hiding filter for each generated CSS selector
- if (selectors.length > 0)
- {
- let domain = getDecodedHostname(baseURL).replace(/^www\./, "");
+ // Add an element hiding filter for each generated CSS selector
+ if (selectors.length > 0)
+ {
+ let domain = getDecodedHostname(baseURL).replace(/^www\./, "");
- for (let selector of selectors)
- filters.push(domain + "##" + selector);
+ for (let selector of selectors)
+ filters.push(domain + "##" + selector);
+ }
}
return {filters: filters, selectors: selectors};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld