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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (element.style.getPropertyValue("display") != "none" || | 113 if (element.style.getPropertyValue("display") != "none" || |
114 element.style.getPropertyPriority("display") != "important") | 114 element.style.getPropertyPriority("display") != "important") |
115 { | 115 { |
116 element.style.setProperty("display", "none", "important"); | 116 element.style.setProperty("display", "none", "important"); |
117 } | 117 } |
118 }) | 118 }) |
119 .observe(element, {attributes: true, attributeFilter: ["style"]}); | 119 .observe(element, {attributes: true, attributeFilter: ["style"]}); |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
| 123 * Observes changes to a DOM node using a <code>MutationObserver</code>. |
| 124 * |
| 125 * @param {Node} target The DOM node to observe for changes. |
| 126 * @param {MutationObserverInit?} [options] Options that describe what DOM |
| 127 * mutations should be reported to the callback. |
| 128 * @param {function} callback A function that will be called on each DOM |
| 129 * mutation, taking a <code>MutationRecord</code> as its parameter. |
| 130 */ |
| 131 function observe(target, options, callback) |
| 132 { |
| 133 new MutationObserver(mutations => |
| 134 { |
| 135 for (let mutation of mutations) |
| 136 callback(mutation); |
| 137 }) |
| 138 .observe(target, options); |
| 139 } |
| 140 |
| 141 /** |
123 * Logs its arguments to the console. This may be used for testing and | 142 * Logs its arguments to the console. This may be used for testing and |
124 * debugging. | 143 * debugging. |
125 * | 144 * |
126 * @param {...*} [args] The arguments to log. | 145 * @param {...*} [args] The arguments to log. |
127 */ | 146 */ |
128 function log(...args) | 147 function log(...args) |
129 { | 148 { |
130 console.log(...args); | 149 console.log(...args); |
131 } | 150 } |
132 | 151 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // will be removed. | 252 // will be removed. |
234 shadows.set(observer, {host: this, root}); | 253 shadows.set(observer, {host: this, root}); |
235 | 254 |
236 return root; | 255 return root; |
237 } | 256 } |
238 }); | 257 }); |
239 } | 258 } |
240 | 259 |
241 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains, | 260 exports["hide-if-shadow-contains"] = makeInjector(hideIfShadowContains, |
242 hideElement); | 261 hideElement); |
| 262 |
| 263 /** |
| 264 * Readds to the document any removed HTML elements that match a CSS selector. |
| 265 * |
| 266 * @param {string} selector The CSS selector that a removed HTML element should |
| 267 * match for it to be added back. |
| 268 * @param {string?} [parentSelector] The CSS selector that a removed HTML |
| 269 * element's former parent should match for it to be added back. |
| 270 */ |
| 271 function readd(selector, parentSelector = null) |
| 272 { |
| 273 observe(document, {childList: true, subtree: true}, mutation => |
| 274 { |
| 275 if (mutation.removedNodes && |
| 276 (!parentSelector || (mutation.target instanceof Element && |
| 277 mutation.target.matches(parentSelector)))) |
| 278 { |
| 279 for (let node of mutation.removedNodes) |
| 280 { |
| 281 if (node instanceof HTMLElement && node.matches(selector)) |
| 282 { |
| 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. |
| 285 mutation.target.appendChild(node); |
| 286 } |
| 287 } |
| 288 } |
| 289 }); |
| 290 } |
| 291 |
| 292 exports.readd = readd; |
OLD | NEW |