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

Side by Side Diff: include.preload.js

Issue 29341245: Issue 4038 - Add element hiding rules in larger chunks (Closed)
Patch Set: Created May 11, 2016, 5:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 18 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
19 var SELECTOR_GROUP_SIZE = 20; 19 var SELECTOR_GROUP_SIZE = 200;
20 20
21 var typeMap = { 21 var typeMap = {
22 "img": "IMAGE", 22 "img": "IMAGE",
23 "input": "IMAGE", 23 "input": "IMAGE",
24 "picture": "IMAGE", 24 "picture": "IMAGE",
25 "audio": "MEDIA", 25 "audio": "MEDIA",
26 "video": "MEDIA", 26 "video": "MEDIA",
27 "frame": "SUBDOCUMENT", 27 "frame": "SUBDOCUMENT",
28 "iframe": "SUBDOCUMENT", 28 "iframe": "SUBDOCUMENT",
29 "object": "OBJECT", 29 "object": "OBJECT",
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 var preparedSelectors = []; 450 var preparedSelectors = [];
451 for (var i = 0; i < selectors.length; i++) 451 for (var i = 0; i < selectors.length; i++)
452 { 452 {
453 var subSelectors = splitSelector(selectors[i]); 453 var subSelectors = splitSelector(selectors[i]);
454 for (var j = 0; j < subSelectors.length; j++) 454 for (var j = 0; j < subSelectors.length; j++)
455 preparedSelectors.push("::content " + subSelectors[j]); 455 preparedSelectors.push("::content " + subSelectors[j]);
456 } 456 }
457 selectors = preparedSelectors; 457 selectors = preparedSelectors;
458 } 458 }
459 459
460 // WebKit (and Blink?) apparently chokes when the selector list in a 460 // Safari only allows 8192 primitive selectors to be injected at once[1], we
461 // CSS rule is huge. So we split the elemhide selectors into groups. 461 // therefore chunk the inserted selectors into groups of 200 to be safe.
462 // (Chrome also has a limit, larger... but we're not certain exactly what it
463 // is! Edge apparently has no such limit.)
464 // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69 debb75fc1de/Source/WebCore/css/RuleSet.h#L68
462 for (var i = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE) 465 for (var i = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE)
463 { 466 {
464 var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", "); 467 var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", ");
465 style.sheet.addRule(selector, "display: none !important;"); 468 style.sheet.addRule(selector, "display: none !important;");
466 } 469 }
467 }; 470 };
468 471
469 var updateStylesheet = function() 472 var updateStylesheet = function()
470 { 473 {
471 var selectors = null; 474 var selectors = null;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 }, true); 555 }, true);
553 556
554 return updateStylesheet; 557 return updateStylesheet;
555 } 558 }
556 559
557 if (document instanceof HTMLDocument) 560 if (document instanceof HTMLDocument)
558 { 561 {
559 checkSitekey(); 562 checkSitekey();
560 window.updateStylesheet = init(document); 563 window.updateStylesheet = init(document);
561 } 564 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld