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

Unified Diff: include.preload.js

Issue 29401596: Issue 5094 - Implement support for :has() in chrome extension (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rebased. With the proper revision in dependencies. Created June 14, 2017, 2:21 a.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
« dependencies ('K') | « dependencies ('k') | lib/filterValidation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -122,16 +122,43 @@
{
if (/^(?!https?:)[\w-]+:/i.test(urls[i]))
urls.splice(i--, 1);
}
return urls;
}
+function hideElement(element)
+{
+ function doHide(el)
+ {
+ let propertyName = "display";
+ let propertyValue = "none";
+ if (el.localName == "frame")
+ {
+ propertyName = "visibility";
+ propertyValue = "hidden";
+ }
+
+ if (el.style.getPropertyValue(propertyName) != propertyValue ||
+ el.style.getPropertyPriority(propertyName) != "important")
+ el.style.setProperty(propertyName, propertyValue, "important");
+ }
+
+ doHide(element);
+
+ new MutationObserver(doHide).observe(
+ element, {
+ attributes: true,
+ attributeFilter: ["style"]
+ }
+ );
+}
+
function checkCollapse(element)
{
let mediatype = typeMap.get(element.localName);
if (!mediatype)
return;
let urls = getURLsFromElement(element);
if (urls.length == 0)
@@ -142,41 +169,19 @@
type: "filters.collapse",
urls,
mediatype,
baseURL: document.location.href
},
collapse =>
{
- function collapseElement()
- {
- let propertyName = "display";
- let propertyValue = "none";
- if (element.localName == "frame")
- {
- propertyName = "visibility";
- propertyValue = "hidden";
- }
-
- if (element.style.getPropertyValue(propertyName) != propertyValue ||
- element.style.getPropertyPriority(propertyName) != "important")
- element.style.setProperty(propertyName, propertyValue, "important");
- }
-
if (collapse)
{
- collapseElement();
-
- new MutationObserver(collapseElement).observe(
- element, {
- attributes: true,
- attributeFilter: ["style"]
- }
- );
+ hideElement(element);
}
}
);
}
function checkSitekey()
{
let attr = document.documentElement.getAttribute("data-adblockkey");
@@ -343,17 +348,18 @@
window,
callback =>
{
ext.backgroundPage.sendMessage({
type: "filters.get",
what: "elemhideemulation"
}, callback);
},
- this.addSelectors.bind(this)
+ this.addSelectors.bind(this),
+ this.hideElements.bind(this)
);
}
ElemHide.prototype = {
selectorGroupSize: 200,
createShadowTree()
{
// Use Shadow DOM if available as to not mess with with web pages that
@@ -432,16 +438,29 @@
this.style.sheet.insertRule(selector + "{display: none !important;}",
this.style.sheet.cssRules.length);
}
if (this.tracer)
this.tracer.addSelectors(selectors, filters);
},
+ hideElements(elements, filters)
+ {
+ for (let element of elements)
+ hideElement(element);
+
+ if (this.tracer)
kzar 2017/06/14 10:20:30 Nit: Since this if clause spans multiple lines ple
hub 2017/06/14 15:49:27 it did pass ESLint. Adding the braces.
+ ext.backgroundPage.sendMessage({
+ type: "devtools.traceElemHide",
+ selectors: [],
+ filters
+ });
+ },
+
apply()
{
ext.backgroundPage.sendMessage({type: "get-selectors"}, response =>
{
if (this.tracer)
this.tracer.disconnect();
this.tracer = null;
« dependencies ('K') | « dependencies ('k') | lib/filterValidation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld