| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 158 } |
| 159 if (match[1] == "properties") | 159 if (match[1] == "properties") |
| 160 selectors.push(new PropsSelector(content.text)); | 160 selectors.push(new PropsSelector(content.text)); |
| 161 else if (match[1] == "has") | 161 else if (match[1] == "has") |
| 162 { | 162 { |
| 163 let hasSelector = new HasSelector(content.text); | 163 let hasSelector = new HasSelector(content.text); |
| 164 if (!hasSelector.valid()) | 164 if (!hasSelector.valid()) |
| 165 return null; | 165 return null; |
| 166 selectors.push(hasSelector); | 166 selectors.push(hasSelector); |
| 167 } | 167 } |
| 168 else if (match[1] == "contains") |
| 169 selectors.push(new ContainsSelector(content.text)); |
| 168 else | 170 else |
| 169 { | 171 { |
| 170 // this is an error, can't parse selector. | 172 // this is an error, can't parse selector. |
| 171 console.error(new SyntaxError("Failed parsing AdBlock Plus " + | 173 console.error(new SyntaxError("Failed parsing AdBlock Plus " + |
| 172 `selector ${selector}, invalid ` + | 174 `selector ${selector}, invalid ` + |
| 173 `pseudo-class -abp-${match[1]}().`)); | 175 `pseudo-class -abp-${match[1]}().`)); |
| 174 return null; | 176 return null; |
| 175 } | 177 } |
| 176 | 178 |
| 177 let suffix = parseSelector(selector.substr(content.end + 1)); | 179 let suffix = parseSelector(selector.substr(content.end + 1)); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 element, styles); | 284 element, styles); |
| 283 for (let selector of iter) | 285 for (let selector of iter) |
| 284 // we insert a space between the two. It becomes a no-op if selector | 286 // we insert a space between the two. It becomes a no-op if selector |
| 285 // doesn't have a combinator | 287 // doesn't have a combinator |
| 286 if (subtree.querySelector(selector)) | 288 if (subtree.querySelector(selector)) |
| 287 yield element; | 289 yield element; |
| 288 } | 290 } |
| 289 } | 291 } |
| 290 }; | 292 }; |
| 291 | 293 |
| 294 function ContainsSelector(textContent) |
| 295 { |
| 296 this._text = textContent; |
| 297 } |
| 298 |
| 299 ContainsSelector.prototype = { |
| 300 requiresHiding: true, |
| 301 |
| 302 *getSelectors(prefix, subtree, stylesheet) |
| 303 { |
| 304 for (let element of this.getElements(prefix, subtree, stylesheet)) |
| 305 yield [makeSelector(element, ""), subtree]; |
| 306 }, |
| 307 |
| 308 *getElements(prefix, subtree, stylesheet) |
| 309 { |
| 310 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
| 311 prefix + "*" : prefix; |
| 312 let elements = subtree.querySelectorAll(actualPrefix); |
| 313 for (let element of elements) |
| 314 if (element.textContent == this._text) |
| 315 yield element; |
| 316 } |
| 317 }; |
| 318 |
| 292 function PropsSelector(propertyExpression) | 319 function PropsSelector(propertyExpression) |
| 293 { | 320 { |
| 294 let regexpString; | 321 let regexpString; |
| 295 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | 322 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && |
| 296 propertyExpression[propertyExpression.length - 1] == "/") | 323 propertyExpression[propertyExpression.length - 1] == "/") |
| 297 { | 324 { |
| 298 regexpString = propertyExpression.slice(1, -1) | 325 regexpString = propertyExpression.slice(1, -1) |
| 299 .replace("\\x7B ", "{").replace("\\x7D ", "}"); | 326 .replace("\\x7B ", "{").replace("\\x7D ", "}"); |
| 300 } | 327 } |
| 301 else | 328 else |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 446 |
| 420 if (this.patterns.length > 0) | 447 if (this.patterns.length > 0) |
| 421 { | 448 { |
| 422 let {document} = this.window; | 449 let {document} = this.window; |
| 423 this.addSelectors(document.styleSheets); | 450 this.addSelectors(document.styleSheets); |
| 424 document.addEventListener("load", this.onLoad.bind(this), true); | 451 document.addEventListener("load", this.onLoad.bind(this), true); |
| 425 } | 452 } |
| 426 }); | 453 }); |
| 427 } | 454 } |
| 428 }; | 455 }; |
| OLD | NEW |