Left: | ||
Right: |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 }; | 190 }; |
191 | 191 |
192 const incompletePrefixRegexp = /[\s>+~]$/; | 192 const incompletePrefixRegexp = /[\s>+~]$/; |
193 | 193 |
194 function HasSelector(selectors) | 194 function HasSelector(selectors) |
195 { | 195 { |
196 this._innerSelectors = selectors; | 196 this._innerSelectors = selectors; |
197 } | 197 } |
198 | 198 |
199 HasSelector.prototype = { | 199 HasSelector.prototype = { |
200 requiresHiding: true, | |
201 | |
202 *getSelectors(prefix, subtree, styles) | 200 *getSelectors(prefix, subtree, styles) |
203 { | 201 { |
204 for (let element of this.getElements(prefix, subtree, styles)) | 202 for (let element of this.getElements(prefix, subtree, styles)) |
205 yield [makeSelector(element, ""), element]; | 203 yield [makeSelector(element, ""), element]; |
206 }, | 204 }, |
207 | 205 |
208 /** | 206 /** |
209 * Generator function returning selected elements. | 207 * Generator function returning selected elements. |
210 * @param {string} prefix the prefix for the selector. | 208 * @param {string} prefix the prefix for the selector. |
211 * @param {Node} subtree the subtree we work on. | 209 * @param {Node} subtree the subtree we work on. |
(...skipping 27 matching lines...) Expand all Loading... | |
239 regexpString = propertyExpression.slice(1, -1) | 237 regexpString = propertyExpression.slice(1, -1) |
240 .replace("\\x7B ", "{").replace("\\x7D ", "}"); | 238 .replace("\\x7B ", "{").replace("\\x7D ", "}"); |
241 } | 239 } |
242 else | 240 else |
243 regexpString = filterToRegExp(propertyExpression); | 241 regexpString = filterToRegExp(propertyExpression); |
244 | 242 |
245 this._regexp = new RegExp(regexpString, "i"); | 243 this._regexp = new RegExp(regexpString, "i"); |
246 } | 244 } |
247 | 245 |
248 PropsSelector.prototype = { | 246 PropsSelector.prototype = { |
247 hideWithStyleSheet: true, | |
248 | |
249 *findPropsSelectors(styles, prefix, regexp) | 249 *findPropsSelectors(styles, prefix, regexp) |
250 { | 250 { |
251 for (let style of styles) | 251 for (let style of styles) |
252 if (regexp.test(style.style)) | 252 if (regexp.test(style.style)) |
253 for (let subSelector of style.subSelectors) | 253 for (let subSelector of style.subSelectors) |
254 yield prefix + subSelector; | 254 yield prefix + subSelector; |
255 }, | 255 }, |
256 | 256 |
257 *getSelectors(prefix, subtree, styles) | 257 *getSelectors(prefix, subtree, styles) |
258 { | 258 { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 cssStyles.push(stringifyStyle(rule)); | 370 cssStyles.push(stringifyStyle(rule)); |
371 } | 371 } |
372 } | 372 } |
373 | 373 |
374 let {document} = this.window; | 374 let {document} = this.window; |
375 for (let pattern of this.patterns) | 375 for (let pattern of this.patterns) |
376 { | 376 { |
377 for (let selector of evaluate(pattern.selectors, | 377 for (let selector of evaluate(pattern.selectors, |
378 0, "", document, cssStyles)) | 378 0, "", document, cssStyles)) |
379 { | 379 { |
380 if (!pattern.selectors.some(s => s.requiresHiding)) | 380 if (pattern.selectors.some(s => s.hideWithStyleSheet)) |
Wladimir Palant
2017/06/19 08:28:32
This logic reversal is wrong - any filter containi
hub
2017/06/19 13:37:15
Done.
| |
381 { | 381 { |
382 selectors.push(selector); | 382 selectors.push(selector); |
383 selectorFilters.push(pattern.text); | 383 selectorFilters.push(pattern.text); |
384 } | 384 } |
385 else | 385 else |
386 { | 386 { |
387 for (let element of document.querySelectorAll(selector)) | 387 for (let element of document.querySelectorAll(selector)) |
388 { | 388 { |
389 elements.push(element); | 389 elements.push(element); |
390 elementFilters.push(pattern.text); | 390 elementFilters.push(pattern.text); |
(...skipping 27 matching lines...) Expand all Loading... | |
418 | 418 |
419 if (this.patterns.length > 0) | 419 if (this.patterns.length > 0) |
420 { | 420 { |
421 let {document} = this.window; | 421 let {document} = this.window; |
422 this.addSelectors(document.styleSheets); | 422 this.addSelectors(document.styleSheets); |
423 document.addEventListener("load", this.onLoad.bind(this), true); | 423 document.addEventListener("load", this.onLoad.bind(this), true); |
424 } | 424 } |
425 }); | 425 }); |
426 } | 426 } |
427 }; | 427 }; |
OLD | NEW |