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: Rebased on patch for issue 3143. Created June 1, 2017, 6:29 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') | no next file with comments »
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (match[1] == "properties") 162 if (match[1] == "properties")
163 selectors.push(new PropsSelector(content.text)); 163 selectors.push(new PropsSelector(content.text));
164 else if (match[1] == "has") 164 else if (match[1] == "has")
165 { 165 {
166 let hasSelector = new HasSelector(content.text); 166 let hasSelector = new HasSelector(content.text);
167 if (!hasSelector.valid()) 167 if (!hasSelector.valid())
168 return {selectors: null, hide: false}; 168 return {selectors: null, hide: false};
169 selectors.push(hasSelector); 169 selectors.push(hasSelector);
170 hide = true; 170 hide = true;
171 } 171 }
172 else if (match[1] == "contains")
173 {
174 selectors.push(new ContainsSelector(content.text));
175 hide = true;
176 }
172 else 177 else
173 { 178 {
174 // this is an error, can't parse selector. 179 // this is an error, can't parse selector.
175 console.error(new SyntaxError("Failed parsing AdBlock Plus " + 180 console.error(new SyntaxError("Failed parsing AdBlock Plus " +
176 `selector ${selector}, invalid ` + 181 `selector ${selector}, invalid ` +
177 `pseudo-class -abp-${match[1]}().`)); 182 `pseudo-class -abp-${match[1]}().`));
178 return {selectors: null, hide: false}; 183 return {selectors: null, hide: false};
179 } 184 }
180 185
181 suffixStart = startIndex + content.end + 1; 186 suffixStart = startIndex + content.end + 1;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 element, styles); 279 element, styles);
275 for (let selector of iter) 280 for (let selector of iter)
276 // we insert a space between the two. It becomes a no-op if selector 281 // we insert a space between the two. It becomes a no-op if selector
277 // doesn't have a combinator 282 // doesn't have a combinator
278 if (subtree.querySelector(selector)) 283 if (subtree.querySelector(selector))
279 yield element; 284 yield element;
280 } 285 }
281 } 286 }
282 }; 287 };
283 288
289 function ContainsSelector(textContent)
290 {
291 this._text = textContent;
292 }
293
294 ContainsSelector.prototype = {
295
296 *getSelectors(prefix, subtree, stylesheet)
297 {
298 for (let element of this.getElements(prefix, subtree, stylesheet))
299 yield [makeSelector(element, ""), subtree];
300 },
301
302 *getElements(prefix, subtree, stylesheet)
303 {
304 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ?
305 prefix + "*" : prefix;
306 let elements = subtree.querySelectorAll(actualPrefix);
307 for (let element of elements)
308 if (element.textContent == this._text)
309 yield element;
310 }
311 };
312
284 function PropsSelector(propertyExpression) 313 function PropsSelector(propertyExpression)
285 { 314 {
286 let regexpString; 315 let regexpString;
287 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && 316 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" &&
288 propertyExpression[propertyExpression.length - 1] == "/") 317 propertyExpression[propertyExpression.length - 1] == "/")
289 { 318 {
290 regexpString = propertyExpression.slice(1, -1) 319 regexpString = propertyExpression.slice(1, -1)
291 .replace("\\x7B ", "{").replace("\\x7D ", "}"); 320 .replace("\\x7B ", "{").replace("\\x7D ", "}");
292 } 321 }
293 else 322 else
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 436
408 if (this.patterns.length > 0) 437 if (this.patterns.length > 0)
409 { 438 {
410 let {document} = this.window; 439 let {document} = this.window;
411 this.addSelectors(document.styleSheets); 440 this.addSelectors(document.styleSheets);
412 document.addEventListener("load", this.onLoad.bind(this), true); 441 document.addEventListener("load", this.onLoad.bind(this), true);
413 } 442 }
414 }); 443 });
415 } 444 }
416 }; 445 };
OLDNEW
« no previous file with comments | « no previous file | test/browser/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld