| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 { | 248 { |
| 249 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 249 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
| 250 prefix + "*" : prefix; | 250 prefix + "*" : prefix; |
| 251 let elements = subtree.querySelectorAll(actualPrefix); | 251 let elements = subtree.querySelectorAll(actualPrefix); |
| 252 for (let element of elements) | 252 for (let element of elements) |
| 253 if (element.textContent.includes(this._text)) | 253 if (element.textContent.includes(this._text)) |
| 254 yield element; | 254 yield element; |
| 255 } | 255 } |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 function PropsSelector(propertyExpression) | 258 function PropsSelector(propertyExpression, pseudoElem) |
| 259 { | 259 { |
| 260 let regexpString; | 260 let regexpString; |
| 261 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | 261 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && |
| 262 propertyExpression[propertyExpression.length - 1] == "/") | 262 propertyExpression[propertyExpression.length - 1] == "/") |
| 263 { | 263 { |
| 264 regexpString = propertyExpression.slice(1, -1) | 264 regexpString = propertyExpression.slice(1, -1) |
| 265 .replace("\\x7B ", "{").replace("\\x7D ", "}"); | 265 .replace("\\x7B ", "{").replace("\\x7D ", "}"); |
| 266 } | 266 } |
| 267 else | 267 else |
| 268 regexpString = filterToRegExp(propertyExpression); | 268 regexpString = filterToRegExp(propertyExpression); |
| 269 | 269 |
| 270 this._regexp = new RegExp(regexpString, "i"); | 270 this._regexp = new RegExp(regexpString, "i"); |
| 271 this._pseudoElem = pseudoElem || ""; |
| 271 } | 272 } |
| 272 | 273 |
| 273 PropsSelector.prototype = { | 274 PropsSelector.prototype = { |
| 274 preferHideWithSelector: true, | 275 preferHideWithSelector: true, |
| 275 | 276 |
| 276 *findPropsSelectors(styles, prefix, regexp) | 277 *findPropsSelectors(styles, prefix, regexp) |
| 277 { | 278 { |
| 278 for (let style of styles) | 279 for (let style of styles) |
| 279 if (regexp.test(style.style)) | 280 if (regexp.test(style.style)) |
| 280 for (let subSelector of style.subSelectors) | 281 for (let subSelector of style.subSelectors) |
| 282 { |
| 283 if (this._pseudoElem) |
| 284 { |
| 285 let idx = subSelector.lastIndexOf(this._pseudoElem); |
| 286 if (idx != subSelector.length - this._pseudoElem.length) |
| 287 continue; |
| 288 if (idx > 0 && subSelector[idx - 1] == ":") |
| 289 idx--; |
| 290 subSelector = subSelector.substring(0, idx); |
| 291 } |
| 281 yield prefix + subSelector; | 292 yield prefix + subSelector; |
| 293 } |
| 282 }, | 294 }, |
| 283 | 295 |
| 284 *getSelectors(prefix, subtree, styles) | 296 *getSelectors(prefix, subtree, styles) |
| 285 { | 297 { |
| 286 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp)) | 298 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp)) |
| 287 yield [selector, subtree]; | 299 yield [selector, subtree]; |
| 288 } | 300 } |
| 289 }; | 301 }; |
| 290 | 302 |
| 291 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc, | 303 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 if (!content) | 346 if (!content) |
| 335 { | 347 { |
| 336 this.window.console.error( | 348 this.window.console.error( |
| 337 new SyntaxError("Failed to parse Adblock Plus " + | 349 new SyntaxError("Failed to parse Adblock Plus " + |
| 338 `selector ${selector} ` + | 350 `selector ${selector} ` + |
| 339 "due to unmatched parentheses.")); | 351 "due to unmatched parentheses.")); |
| 340 return null; | 352 return null; |
| 341 } | 353 } |
| 342 if (match[1] == "properties") | 354 if (match[1] == "properties") |
| 343 selectors.push(new PropsSelector(content.text)); | 355 selectors.push(new PropsSelector(content.text)); |
| 356 else if (match[1] == "properties-before") |
| 357 selectors.push(new PropsSelector(content.text, ":before")); |
| 358 else if (match[1] == "properties-after") |
| 359 selectors.push(new PropsSelector(content.text, ":after")); |
| 344 else if (match[1] == "has") | 360 else if (match[1] == "has") |
| 345 { | 361 { |
| 346 let hasSelectors = this.parseSelector(content.text); | 362 let hasSelectors = this.parseSelector(content.text); |
| 347 if (hasSelectors == null) | 363 if (hasSelectors == null) |
| 348 return null; | 364 return null; |
| 349 selectors.push(new HasSelector(hasSelectors)); | 365 selectors.push(new HasSelector(hasSelectors)); |
| 350 } | 366 } |
| 351 else if (match[1] == "contains") | 367 else if (match[1] == "contains") |
| 352 selectors.push(new ContainsSelector(content.text)); | 368 selectors.push(new ContainsSelector(content.text)); |
| 353 else | 369 else |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 474 |
| 459 if (this.patterns.length > 0) | 475 if (this.patterns.length > 0) |
| 460 { | 476 { |
| 461 let {document} = this.window; | 477 let {document} = this.window; |
| 462 this.addSelectors(document.styleSheets); | 478 this.addSelectors(document.styleSheets); |
| 463 document.addEventListener("load", this.onLoad.bind(this), true); | 479 document.addEventListener("load", this.onLoad.bind(this), true); |
| 464 } | 480 } |
| 465 }); | 481 }); |
| 466 } | 482 } |
| 467 }; | 483 }; |
| OLD | NEW |