| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3  * Copyright (C) 2006-2015 Eyeo GmbH | 3  * Copyright (C) 2006-2015 Eyeo GmbH | 
| 4  * | 4  * | 
| 5  * Adblock Plus is free software: you can redistribute it and/or modify | 5  * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6  * it under the terms of the GNU General Public License version 3 as | 6  * it under the terms of the GNU General Public License version 3 as | 
| 7  * published by the Free Software Foundation. | 7  * published by the Free Software Foundation. | 
| 8  * | 8  * | 
| 9  * Adblock Plus is distributed in the hope that it will be useful, | 9  * Adblock Plus is distributed in the hope that it will be useful, | 
| 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 97   } | 97   } | 
| 98 } | 98 } | 
| 99 | 99 | 
| 100 function resolveURL(url) | 100 function resolveURL(url) | 
| 101 { | 101 { | 
| 102   var a = document.createElement("a"); | 102   var a = document.createElement("a"); | 
| 103   a.href = url; | 103   a.href = url; | 
| 104   return a.href; | 104   return a.href; | 
| 105 } | 105 } | 
| 106 | 106 | 
|  | 107 function traceHiddenElements(document, selectors) | 
|  | 108 { | 
|  | 109   function check(element) | 
|  | 110   { | 
|  | 111     var matchedSelectors = []; | 
|  | 112 | 
|  | 113     for (var i = 0; i < selectors.length; i++) | 
|  | 114     { | 
|  | 115       var selector = selectors[i]; | 
|  | 116       var elements = document.querySelectorAll(selector); | 
|  | 117 | 
|  | 118       for (var j = 0; j < elements.length; j++) | 
|  | 119       { | 
|  | 120         if (getComputedStyle(elements[j]).display == "none") | 
|  | 121         { | 
|  | 122           matchedSelectors.push(selector); | 
|  | 123           break; | 
|  | 124         } | 
|  | 125       } | 
|  | 126     } | 
|  | 127 | 
|  | 128     if (matchedSelectors.length > 0) | 
|  | 129       ext.backgroundPage.sendMessage({type: "trace-elemhide", selectors: matched
     Selectors}); | 
|  | 130   } | 
|  | 131 | 
|  | 132   function trace() | 
|  | 133   { | 
|  | 134     check(); | 
|  | 135 | 
|  | 136     new MutationObserver(check).observe( | 
|  | 137       document, | 
|  | 138       { | 
|  | 139         childList: true, | 
|  | 140         attributes: true, | 
|  | 141         subtree: true | 
|  | 142       } | 
|  | 143     ); | 
|  | 144   } | 
|  | 145 | 
|  | 146   if (document.readyState == "loading") | 
|  | 147     document.addEventListener("DOMContentLoaded", trace); | 
|  | 148   else | 
|  | 149     trace(); | 
|  | 150 } | 
|  | 151 | 
| 107 function reinjectRulesWhenRemoved(document, style) | 152 function reinjectRulesWhenRemoved(document, style) | 
| 108 { | 153 { | 
| 109   var MutationObserver = window.MutationObserver || window.WebKitMutationObserve
     r; | 154   var MutationObserver = window.MutationObserver || window.WebKitMutationObserve
     r; | 
| 110   if (!MutationObserver) | 155   if (!MutationObserver) | 
| 111     return; | 156     return; | 
| 112 | 157 | 
| 113   var observer = new MutationObserver(function(mutations) | 158   var observer = new MutationObserver(function(mutations) | 
| 114   { | 159   { | 
| 115     var isStyleRemoved = false; | 160     var isStyleRemoved = false; | 
| 116     for (var i = 0; i < mutations.length; i++) | 161     for (var i = 0; i < mutations.length; i++) | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 196   // Also, we can't use shadow DOM on Google Docs, since it breaks printing | 241   // Also, we can't use shadow DOM on Google Docs, since it breaks printing | 
| 197   // there (#1770). | 242   // there (#1770). | 
| 198   var shadow = null; | 243   var shadow = null; | 
| 199   if ("createShadowRoot" in document.documentElement && document.domain != "docs
     .google.com") | 244   if ("createShadowRoot" in document.documentElement && document.domain != "docs
     .google.com") | 
| 200   { | 245   { | 
| 201     shadow = document.documentElement.createShadowRoot(); | 246     shadow = document.documentElement.createShadowRoot(); | 
| 202     shadow.appendChild(document.createElement("shadow")); | 247     shadow.appendChild(document.createElement("shadow")); | 
| 203   } | 248   } | 
| 204 | 249 | 
| 205   // Sets the currently used CSS rules for elemhide filters | 250   // Sets the currently used CSS rules for elemhide filters | 
| 206   var setElemhideCSSRules = function(selectors) | 251   var setElemhideCSSRules = function(response) | 
| 207   { | 252   { | 
| 208     if (selectors.length == 0) | 253     if (response.selectors.length == 0) | 
| 209       return; | 254       return; | 
| 210 | 255 | 
| 211     var style = document.createElement("style"); | 256     var style = document.createElement("style"); | 
| 212     style.setAttribute("type", "text/css"); | 257     style.setAttribute("type", "text/css"); | 
| 213 | 258 | 
|  | 259     var selectors = response.selectors; | 
| 214     if (shadow) | 260     if (shadow) | 
| 215     { | 261     { | 
| 216       shadow.appendChild(style); | 262       shadow.appendChild(style); | 
| 217       selectors = convertSelectorsForShadowDOM(selectors); | 263       selectors = convertSelectorsForShadowDOM(selectors); | 
| 218     } | 264     } | 
| 219     else | 265     else | 
| 220     { | 266     { | 
| 221       // Try to insert the style into the <head> tag, inserting directly under t
     he | 267       // Try to insert the style into the <head> tag, inserting directly under t
     he | 
| 222       // document root breaks dev tools functionality: | 268       // document root breaks dev tools functionality: | 
| 223       // http://code.google.com/p/chromium/issues/detail?id=178109 | 269       // http://code.google.com/p/chromium/issues/detail?id=178109 | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 234         return; | 280         return; | 
| 235       } | 281       } | 
| 236 | 282 | 
| 237       // WebKit apparently chokes when the selector list in a CSS rule is huge. | 283       // WebKit apparently chokes when the selector list in a CSS rule is huge. | 
| 238       // So we split the elemhide selectors into groups. | 284       // So we split the elemhide selectors into groups. | 
| 239       for (var i = 0; selectors.length > 0; i++) | 285       for (var i = 0; selectors.length > 0; i++) | 
| 240       { | 286       { | 
| 241         var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); | 287         var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); | 
| 242         style.sheet.insertRule(selector + " { display: none !important; }", i); | 288         style.sheet.insertRule(selector + " { display: none !important; }", i); | 
| 243       } | 289       } | 
|  | 290 | 
|  | 291       if (response.trace) | 
|  | 292         traceHiddenElements(document, response.selectors); | 
| 244     }; | 293     }; | 
| 245 | 294 | 
| 246     setRules(); | 295     setRules(); | 
| 247     reinjectRulesWhenRemoved(document, style); | 296     reinjectRulesWhenRemoved(document, style); | 
| 248   }; | 297   }; | 
| 249 | 298 | 
| 250   document.addEventListener("error", function(event) | 299   document.addEventListener("error", function(event) | 
| 251   { | 300   { | 
| 252     checkCollapse(event.target); | 301     checkCollapse(event.target); | 
| 253   }, true); | 302   }, true); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 273   }, true); | 322   }, true); | 
| 274 | 323 | 
| 275   ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 324   ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 
| 276 } | 325 } | 
| 277 | 326 | 
| 278 if (document instanceof HTMLDocument) | 327 if (document instanceof HTMLDocument) | 
| 279 { | 328 { | 
| 280   checkSitekey(); | 329   checkSitekey(); | 
| 281   init(document); | 330   init(document); | 
| 282 } | 331 } | 
| OLD | NEW | 
|---|