| 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}; |