LEFT | RIGHT |
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 * @param {...*} [args] The arguments to log. | 160 * @param {...*} [args] The arguments to log. |
161 */ | 161 */ |
162 function trace(...args) | 162 function trace(...args) |
163 { | 163 { |
164 // We could simply use console.log here, but the goal is to demonstrate the | 164 // We could simply use console.log here, but the goal is to demonstrate the |
165 // usage of snippet dependencies. | 165 // usage of snippet dependencies. |
166 log(...args); | 166 log(...args); |
167 } | 167 } |
168 | 168 |
169 exports.trace = makeInjector(trace, log); | 169 exports.trace = makeInjector(trace, log); |
| 170 |
| 171 // This is an implementation of the uabinject-defuser technique used by uBlock |
| 172 // Origin |
| 173 // https://github.com/uBlockOrigin/uAssets/blob/c091f861b63cd2254b8e9e4628f6bdcd
89d43caa/filters/resources.txt#L640 |
| 174 function uabinjectDefuser() |
| 175 { |
| 176 window.trckd = true; |
| 177 window.uabpdl = true; |
| 178 window.uabInject = true; |
| 179 window.uabDetect = true; |
| 180 } |
| 181 |
| 182 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); |
170 | 183 |
171 /** | 184 /** |
172 * Hides any HTML element or one of its ancestors matching a CSS selector if | 185 * Hides any HTML element or one of its ancestors matching a CSS selector if |
173 * the text content of the element's shadow contains a given string. | 186 * the text content of the element's shadow contains a given string. |
174 * | 187 * |
175 * @param {string} search The string to look for in every HTML element's | 188 * @param {string} search The string to look for in every HTML element's |
176 * shadow. | 189 * shadow. |
177 * @param {string} selector The CSS selector that an HTML element must match | 190 * @param {string} selector The CSS selector that an HTML element must match |
178 * for it to be hidden. | 191 * for it to be hidden. |
179 */ | 192 */ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 254 |
242 return root; | 255 return root; |
243 } | 256 } |
244 }); | 257 }); |
245 } | 258 } |
246 | 259 |
247 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains, | 260 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains, |
248 hideElement); | 261 hideElement); |
249 | 262 |
250 /** | 263 /** |
251 * 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. |
252 * | 265 * |
253 * @param {string} selector The CSS selector that a removed element should | 266 * @param {string} selector The CSS selector that a removed HTML element should |
254 * match for it to be added back. | 267 * match for it to be added back. |
255 * @param {string?} [parentSelector] The CSS selector that a removed element's | 268 * @param {string?} [parentSelector] The CSS selector that a removed HTML |
256 * former parent should match for it to be added back. | 269 * element's former parent should match for it to be added back. |
257 */ | 270 */ |
258 function untrash(selector, parentSelector = null) | 271 function readd(selector, parentSelector = null) |
259 { | 272 { |
260 observe(document, {childList: true, subtree: true}, mutation => | 273 observe(document, {childList: true, subtree: true}, mutation => |
261 { | 274 { |
262 if (mutation.removedNodes && | 275 if (mutation.removedNodes && |
263 (!parentSelector || mutation.target.matches(parentSelector))) | 276 (!parentSelector || (mutation.target instanceof Element && |
| 277 mutation.target.matches(parentSelector)))) |
264 { | 278 { |
265 for (let node of mutation.removedNodes) | 279 for (let node of mutation.removedNodes) |
266 { | 280 { |
267 if (node instanceof HTMLElement && node.matches(selector)) | 281 if (node instanceof HTMLElement && node.matches(selector)) |
268 { | 282 { |
269 // 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, |
270 // 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. |
271 mutation.target.appendChild(node); | 285 mutation.target.appendChild(node); |
272 } | 286 } |
273 } | 287 } |
274 } | 288 } |
275 }); | 289 }); |
276 } | 290 } |
277 | 291 |
278 exports.untrash = untrash; | 292 exports.readd = readd; |
LEFT | RIGHT |