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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 element, styles); | 223 element, styles); |
224 for (let selector of iter) | 224 for (let selector of iter) |
225 // we insert a space between the two. It becomes a no-op if selector | 225 // we insert a space between the two. It becomes a no-op if selector |
226 // doesn't have a combinator | 226 // doesn't have a combinator |
227 if (subtree.querySelector(selector)) | 227 if (subtree.querySelector(selector)) |
228 yield element; | 228 yield element; |
229 } | 229 } |
230 } | 230 } |
231 }; | 231 }; |
232 | 232 |
| 233 function ContainsSelector(textContent) |
| 234 { |
| 235 this._text = textContent; |
| 236 } |
| 237 |
| 238 ContainsSelector.prototype = { |
| 239 requiresHiding: true, |
| 240 |
| 241 *getSelectors(prefix, subtree, stylesheet) |
| 242 { |
| 243 for (let element of this.getElements(prefix, subtree, stylesheet)) |
| 244 yield [makeSelector(element, ""), subtree]; |
| 245 }, |
| 246 |
| 247 *getElements(prefix, subtree, stylesheet) |
| 248 { |
| 249 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
| 250 prefix + "*" : prefix; |
| 251 let elements = subtree.querySelectorAll(actualPrefix); |
| 252 for (let element of elements) |
| 253 if (element.textContent == this._text) |
| 254 yield element; |
| 255 } |
| 256 }; |
| 257 |
233 function PropsSelector(propertyExpression) | 258 function PropsSelector(propertyExpression) |
234 { | 259 { |
235 let regexpString; | 260 let regexpString; |
236 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | 261 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && |
237 propertyExpression[propertyExpression.length - 1] == "/") | 262 propertyExpression[propertyExpression.length - 1] == "/") |
238 { | 263 { |
239 regexpString = propertyExpression.slice(1, -1) | 264 regexpString = propertyExpression.slice(1, -1) |
240 .replace("\\x7B ", "{").replace("\\x7D ", "}"); | 265 .replace("\\x7B ", "{").replace("\\x7D ", "}"); |
241 } | 266 } |
242 else | 267 else |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 341 } |
317 if (match[1] == "properties") | 342 if (match[1] == "properties") |
318 selectors.push(new PropsSelector(content.text)); | 343 selectors.push(new PropsSelector(content.text)); |
319 else if (match[1] == "has") | 344 else if (match[1] == "has") |
320 { | 345 { |
321 let hasSelectors = this.parseSelector(content.text); | 346 let hasSelectors = this.parseSelector(content.text); |
322 if (hasSelectors == null) | 347 if (hasSelectors == null) |
323 return null; | 348 return null; |
324 selectors.push(new HasSelector(hasSelectors)); | 349 selectors.push(new HasSelector(hasSelectors)); |
325 } | 350 } |
| 351 else if (match[1] == "contains") |
| 352 selectors.push(new ContainsSelector(content.text)); |
326 else | 353 else |
327 { | 354 { |
328 // this is an error, can't parse selector. | 355 // this is an error, can't parse selector. |
329 this.window.console.error( | 356 this.window.console.error( |
330 new SyntaxError("Failed to parse Adblock Plus " + | 357 new SyntaxError("Failed to parse Adblock Plus " + |
331 `selector ${selector}, invalid ` + | 358 `selector ${selector}, invalid ` + |
332 `pseudo-class :-abp-${match[1]}().`)); | 359 `pseudo-class :-abp-${match[1]}().`)); |
333 return null; | 360 return null; |
334 } | 361 } |
335 | 362 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 447 |
421 if (this.patterns.length > 0) | 448 if (this.patterns.length > 0) |
422 { | 449 { |
423 let {document} = this.window; | 450 let {document} = this.window; |
424 this.addSelectors(document.styleSheets); | 451 this.addSelectors(document.styleSheets); |
425 document.addEventListener("load", this.onLoad.bind(this), true); | 452 document.addEventListener("load", this.onLoad.bind(this), true); |
426 } | 453 } |
427 }); | 454 }); |
428 } | 455 } |
429 }; | 456 }; |
OLD | NEW |