Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/elemHideEmulation.js

Issue 29448560: Issue 5249 - Implement :-abp-contains() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Added test for :-abp-contains Created June 21, 2017, 9:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/browser/elemHideEmulation.js » ('j') | test/browser/elemHideEmulation.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
Wladimir Palant 2017/06/28 10:47:24 An exact match is definitely not what we want here
hub 2017/06/28 14:39:10 Done.
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
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
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 };
OLDNEW
« no previous file with comments | « no previous file | test/browser/elemHideEmulation.js » ('j') | test/browser/elemHideEmulation.js » ('J')

Powered by Google App Engine
This is Rietveld