| Index: include.preload.js |
| diff --git a/include.preload.js b/include.preload.js |
| index f4ab60be781c88c27079d7df6f1c4e77a430188d..cbe3b0f9883e398b37e22627eef3c280a2e636ff 100644 |
| --- a/include.preload.js |
| +++ b/include.preload.js |
| @@ -334,22 +334,6 @@ ElementHidingTracer.prototype = { |
| } |
| }; |
| -function reinjectStyleSheetWhenRemoved(document, style) |
| -{ |
| - if (!MutationObserver) |
| - return null; |
| - |
| - var parentNode = style.parentNode; |
| - var observer = new MutationObserver(function() |
| - { |
| - if (style.parentNode != parentNode) |
| - parentNode.appendChild(style); |
| - }); |
| - |
| - observer.observe(parentNode, {childList: true}); |
| - return observer; |
| -} |
| - |
| function runInPage(fn, arg) |
| { |
| var script = document.createElement("script"); |
| @@ -360,33 +344,6 @@ function runInPage(fn, arg) |
| document.documentElement.removeChild(script); |
| } |
| -function protectStyleSheet(document, style) |
| -{ |
| - style.id = id; |
|
Sebastian Noack
2016/08/11 12:38:57
Since the id is only used once (for the WebSocket)
kzar
2016/08/11 12:48:18
Done.
|
| - |
| - runInPage(function(id) |
| - { |
| - var style = document.getElementById(id) || |
| - document.documentElement.shadowRoot.getElementById(id); |
| - style.removeAttribute("id"); |
| - |
| - var disableables = [style, style.sheet]; |
| - for (var i = 0; i < disableables.length; i++) |
| - Object.defineProperty(disableables[i], "disabled", |
| - {value: false, enumerable: true}); |
| - |
| - ["deleteRule", "removeRule"].forEach(function(method) |
| - { |
| - var original = CSSStyleSheet.prototype[method]; |
| - CSSStyleSheet.prototype[method] = function(index) |
| - { |
| - if (this != style.sheet) |
| - original.call(this, index); |
| - }; |
| - }); |
| - }, id); |
| -} |
| - |
| // Neither Chrome[1] nor Safari allow us to intercept WebSockets, and therefore |
| // some ad networks are misusing them as a way to serve adverts and circumvent |
| // us. As a workaround we wrap WebSocket, preventing blocked WebSocket |
| @@ -499,6 +456,22 @@ function init(document) |
| { |
| shadow = document.documentElement.createShadowRoot(); |
| shadow.appendChild(document.createElement("shadow")); |
| + |
| + // Stop the website from messing with our shadowRoot |
| + runInPage(function() |
|
Sebastian Noack
2016/08/11 12:48:11
You have to pass the document to runInPage(), to m
kzar
2016/08/11 13:04:46
Done.
|
| + { |
| + var ourShadowRoot = document.documentElement.shadowRoot; |
| + var desc = Object.getOwnPropertyDescriptor(Element.prototype, "shadowRoot"); |
| + var shadowRoot = Function.prototype.call.bind(desc.get); |
| + |
| + Object.defineProperty(Element.prototype, "shadowRoot", { |
| + conifgurable: true, enumerable: true, get: function() |
| + { |
| + var shadow = shadowRoot(this); |
| + return shadow === ourShadowRoot ? null : shadow; |
|
Sebastian Noack
2016/08/11 12:38:57
Nit: As per Mozilla's coding practices, we prefer
Sebastian Noack
2016/08/11 12:42:37
(The other way around, I meant, == is preferred ov
kzar
2016/08/11 12:48:18
Done.
|
| + } |
| + }); |
| + }, ""); |
|
Sebastian Noack
2016/08/11 12:38:57
Nit: I'd rather pass null, than creating an empty
kzar
2016/08/11 12:48:18
Done.
|
| } |
| function addElemHideSelectors(selectors) |
| @@ -521,9 +494,6 @@ function init(document) |
| // <style> element to the shadow DOM. |
| if (!style.sheet) |
| return; |
| - |
| - observer = reinjectStyleSheetWhenRemoved(document, style); |
| - protectStyleSheet(document, style); |
| } |
| // If using shadow DOM, we have to add the ::content pseudo-element |