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

Delta Between Two Patch Sets: lib/content/snippets.js

Issue 29835561: Issue 6803 - Implement readd snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Revert last two updates and rebase Created July 24, 2018, 2:29 p.m.
Right Patch Set: Rename snippet to "readd" Created July 24, 2018, 3:41 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 | « no previous file | 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 return root; 255 return root;
256 } 256 }
257 }); 257 });
258 } 258 }
259 259
260 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains, 260 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains,
261 hideElement); 261 hideElement);
262 262
263 /** 263 /**
264 * Untrashes a document by readding removed elements that match a CSS selector. 264 * Readds to the document any removed HTML elements that match a CSS selector.
265 * 265 *
266 * @param {string} selector The CSS selector that a removed element should 266 * @param {string} selector The CSS selector that a removed HTML element should
267 * match for it to be added back. 267 * match for it to be added back.
268 * @param {string?} [parentSelector] The CSS selector that a removed element's 268 * @param {string?} [parentSelector] The CSS selector that a removed HTML
269 * former parent should match for it to be added back. 269 * element's former parent should match for it to be added back.
270 */ 270 */
271 function untrash(selector, parentSelector = null) 271 function readd(selector, parentSelector = null)
272 { 272 {
273 observe(document, {childList: true, subtree: true}, mutation => 273 observe(document, {childList: true, subtree: true}, mutation =>
274 { 274 {
275 if (mutation.removedNodes && 275 if (mutation.removedNodes &&
276 (!parentSelector || (mutation.target instanceof Element && 276 (!parentSelector || (mutation.target instanceof Element &&
277 mutation.target.matches(parentSelector)))) 277 mutation.target.matches(parentSelector))))
278 { 278 {
279 for (let node of mutation.removedNodes) 279 for (let node of mutation.removedNodes)
280 { 280 {
281 if (node instanceof HTMLElement && node.matches(selector)) 281 if (node instanceof HTMLElement && node.matches(selector))
282 { 282 {
283 // We don't have the location of the element in its former parent, 283 // We don't have the location of the element in its former parent,
284 // but it's usually OK to just add it at the end. 284 // but it's usually OK to just add it at the end.
285 mutation.target.appendChild(node); 285 mutation.target.appendChild(node);
286 } 286 }
287 } 287 }
288 } 288 }
289 }); 289 });
290 } 290 }
291 291
292 exports.untrash = untrash; 292 exports.readd = readd;
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld