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

Side by Side Diff: lib/content/snippets.js

Issue 29836573: Issue 6809 - Implement hide-if-contains snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created July 23, 2018, 11:11 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-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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // will be removed. 220 // will be removed.
221 shadows.set(observer, {host: this, root}); 221 shadows.set(observer, {host: this, root});
222 222
223 return root; 223 return root;
224 } 224 }
225 }); 225 });
226 } 226 }
227 227
228 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains, 228 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains,
229 hideElement); 229 hideElement);
230
231 /**
232 * Hides any HTML element if the text content of the element contains a given
233 * string.
234 *
235 * @param {string} search The string to look for in every HTML element.
236 * @param {string} selector The CSS selector that an HTML element must match
237 * for it to be hidden.
238 */
239 function hideIfContains(search, selector = "*")
240 {
241 new MutationObserver(() =>
242 {
243 for (let element of document.querySelectorAll(selector))
244 {
245 if (element.textContent.includes(search))
246 hideElement(element);
247 }
248 })
249 .observe(document, {childList: true, characterData: true, subtree: true});
250 }
251
252 exports["hide-if-contains"] = hideIfContains;
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