| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 217 |
| 218 if (selectors.length > 0) | 218 if (selectors.length > 0) |
| 219 { | 219 { |
| 220 // Create <style> element lazily, only if we add styles. Add it to | 220 // Create <style> element lazily, only if we add styles. Add it to |
| 221 // the shadow DOM if possible. Otherwise fallback to the <head> or | 221 // the shadow DOM if possible. Otherwise fallback to the <head> or |
| 222 // <html> element. If we have injected a style element before that | 222 // <html> element. If we have injected a style element before that |
| 223 // has been removed (the sheet property is null), create a new one. | 223 // has been removed (the sheet property is null), create a new one. |
| 224 style = document.createElement("style"); | 224 style = document.createElement("style"); |
| 225 (shadow || document.head || document.documentElement).appendChild(style) ; | 225 (shadow || document.head || document.documentElement).appendChild(style) ; |
| 226 | 226 |
| 227 // It can happen that the frame already navigated to a different documen t | 227 // It can happen that the frame already navigated to a different |
| 228 // while we were waiting for the background page to respond. In that cas e | 228 // document while we were waiting for the background page to respond. |
| 229 // the sheet property will stay null, after addind the <style> element t o | 229 // In that case the sheet property will stay null, after addind the |
| 230 // the shadow DOM. | 230 // <style> element to the shadow DOM. |
|
Wladimir Palant
2015/03/04 21:26:14
Nit: this comment exceeds 80 character boundary no
Sebastian Noack
2015/03/04 21:36:24
Yeah, there is one more indentation level now.
| |
| 231 if (style.sheet) | 231 if (style.sheet) |
| 232 { | 232 { |
| 233 // If using shadow DOM, we have to add the ::content pseudo-element | 233 // If using shadow DOM, we have to add the ::content pseudo-element |
| 234 // before each selector, in order to match elements within the | 234 // before each selector, in order to match elements within the |
| 235 // insertion point. | 235 // insertion point. |
| 236 if (shadow) | 236 if (shadow) |
| 237 selectors = convertSelectorsForShadowDOM(selectors); | 237 selectors = convertSelectorsForShadowDOM(selectors); |
| 238 | 238 |
| 239 // WebKit (and Blink?) apparently chokes when the selector list in a | 239 // WebKit (and Blink?) apparently chokes when the selector list in a |
| 240 // CSS rule is huge. So we split the elemhide selectors into groups. | 240 // CSS rule is huge. So we split the elemhide selectors into groups. |
| 241 while (selectors.length > 0) | 241 for (var i = 0; selectors.length > 0; i++) |
|
Sebastian Noack
2015/03/04 21:36:24
I reverted the loop logic to the simpler one, we h
| |
| 242 { | 242 { |
| 243 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); | 243 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); |
| 244 | 244 style.sheet.insertRule(selector + " { display: none !important; }", i); |
| 245 style.sheet.insertRule( | |
| 246 selector + " { display: none !important; }", | |
| 247 style.sheet.cssRules.length | |
| 248 ); | |
| 249 } | 245 } |
| 250 } | 246 } |
| 251 | 247 |
| 252 observer = reinjectRulesWhenRemoved(document, style); | 248 observer = reinjectRulesWhenRemoved(document, style); |
| 253 } | 249 } |
| 254 }); | 250 }); |
| 255 }; | 251 }; |
| 256 | 252 |
| 257 updateStylesheet(); | 253 updateStylesheet(); |
| 258 | 254 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 282 }, true); | 278 }, true); |
| 283 | 279 |
| 284 return updateStylesheet; | 280 return updateStylesheet; |
| 285 } | 281 } |
| 286 | 282 |
| 287 if (document instanceof HTMLDocument) | 283 if (document instanceof HTMLDocument) |
| 288 { | 284 { |
| 289 checkSitekey(); | 285 checkSitekey(); |
| 290 window.updateStylesheet = init(document); | 286 window.updateStylesheet = init(document); |
| 291 } | 287 } |
| LEFT | RIGHT |