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

Delta Between Two Patch Sets: include.preload.js

Issue 5838948538515456: Issue 370 - Make "Block element" hide elements for added filters (Closed)
Left Patch Set: Replace existing rules Created March 4, 2015, 9:10 p.m.
Right Patch Set: Addressed comments and simplified loop Created March 4, 2015, 9:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « include.postload.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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
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 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld