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

Side by Side Diff: include.preload.js

Issue 29348917: Issue 4191 - Restore rules for reinjected stylesheets (Closed)
Patch Set: Created July 29, 2016, 9:34 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
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 this.observer.disconnect(); 332 this.observer.disconnect();
333 clearTimeout(this.timeout); 333 clearTimeout(this.timeout);
334 } 334 }
335 }; 335 };
336 336
337 function reinjectStyleSheetWhenRemoved(document, style) 337 function reinjectStyleSheetWhenRemoved(document, style)
338 { 338 {
339 if (!MutationObserver) 339 if (!MutationObserver)
340 return null; 340 return null;
341 341
342 var rules = style.sheet.rules;
342 var parentNode = style.parentNode; 343 var parentNode = style.parentNode;
343 var observer = new MutationObserver(function() 344 var observer = new MutationObserver(function()
344 { 345 {
345 if (style.parentNode != parentNode) 346 if (style.parentNode != parentNode)
347 {
346 parentNode.appendChild(style); 348 parentNode.appendChild(style);
349
350 if (style.sheet.rules.length == 0)
351 {
352 for (var i = 0; i < rules.length; i += 1)
353 style.sheet.addRule(rules[i].selectorText, "display: none !important;" );
354
355 style.id = id;
356 injectJS(
357 function(id)
358 {
359 var style = document.getElementById(id) ||
360 document.documentElement.shadowRoot.getElementById(id);
361 style.removeAttribute("id");
362 Object.defineProperty(style.sheet, "disabled",
363 {value: false, enumerable: true});
364 }, id
365 );
366 }
367 }
347 }); 368 });
348 369
349 observer.observe(parentNode, {childList: true}); 370 observer.observe(parentNode, {childList: true});
350 return observer; 371 return observer;
351 } 372 }
352 373
353 function injectJS(f) 374 function injectJS(f)
354 { 375 {
355 var args = JSON.stringify(Array.prototype.slice.call(arguments, 1)); 376 var args = JSON.stringify(Array.prototype.slice.call(arguments, 1));
356 args = args.substring(1, args.length - 1); 377 args = args.substring(1, args.length - 1);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 }, true); 685 }, true);
665 686
666 return updateStylesheet; 687 return updateStylesheet;
667 } 688 }
668 689
669 if (document instanceof HTMLDocument) 690 if (document instanceof HTMLDocument)
670 { 691 {
671 checkSitekey(); 692 checkSitekey();
672 window.updateStylesheet = init(document); 693 window.updateStylesheet = init(document);
673 } 694 }
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