OLD | NEW |
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 Loading... |
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; |
OLD | NEW |