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

Unified Diff: include.preload.js

Issue 5989914281771008: Use Shadow DOM for element hiding (Closed)
Patch Set: Created April 15, 2014, 9:48 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
« no previous file with comments | « background.js ('k') | no next file » | 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
@@ -25,16 +25,24 @@
if (elemhideElt && elemhideElt.parentNode)
elemhideElt.parentNode.removeChild(elemhideElt);
Sebastian Noack 2014/04/15 09:58:06 Storing the inserted <style> tag into a global var
Wladimir Palant 2014/04/15 13:13:14 I somewhat remember that AdThwart had issues with
- if (!selectors)
+ if (selectors.length == 0)
Sebastian Noack 2014/04/15 09:58:06 Skip inserting a style tag, if there are no elemen
Wladimir Palant 2014/04/15 13:13:14 That doesn't make much difference in reality - if
Sebastian Noack 2014/04/15 19:21:54 I am aware that at least when using EASYList there
return;
- elemhideElt = document.createElement("style");
- elemhideElt.setAttribute("type", "text/css");
-
// Try to insert the style into the <head> tag, inserting directly under the
// document root breaks dev tools functionality:
// http://code.google.com/p/chromium/issues/detail?id=178109
- (document.head || document.documentElement).appendChild(elemhideElt);
+ var container = document.head || document.documentElement;
+
+ // Use Shadow DOM if available to don't mess with web pages
+ // that rely on the order of their own <style> tags (#309)
+ if ("createShadowRoot" in container)
+ container = container.createShadowRoot();
Wladimir Palant 2014/04/15 13:13:14 Given that this standard is still very much in flu
Sebastian Noack 2014/04/15 19:21:54 Done.
+ else if ("webkitCreateShadowRoot" in container)
+ container = container.webkitCreateShadowRoot();
Wladimir Palant 2014/04/15 13:13:14 Please add a <shadow> element to our shadow root t
Sebastian Noack 2014/04/15 19:21:54 Done.
+
+ elemhideElt = document.createElement("style");
+ elemhideElt.setAttribute("type", "text/css");
+ container.appendChild(elemhideElt);
Wladimir Palant 2014/04/15 13:13:14 Will these styles affect the regular elements or o
Sebastian Noack 2014/04/15 19:21:54 You are right, it actually didn't worked with the
var elt = elemhideElt; // Use a local variable to avoid racing conditions
function setRules()
« no previous file with comments | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld