| 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-present eyeo GmbH | 3  * Copyright (C) 2006-present 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 | 
| 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 12  * GNU General Public License for more details. | 12  * GNU General Public License for more details. | 
| 13  * | 13  * | 
| 14  * You should have received a copy of the GNU General Public License | 14  * You should have received a copy of the GNU General Public License | 
| 15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
| 16  */ | 16  */ | 
| 17 | 17 | 
| 18 "use strict"; | 18 "use strict"; | 
| 19 | 19 | 
| 20 const {filterToRegExp, splitSelector} = require("../common"); | 20 const {textToRegExp, filterToRegExp, splitSelector} = require("../common"); | 
| 21 | 21 | 
| 22 let MIN_INVOCATION_INTERVAL = 3000; | 22 let MIN_INVOCATION_INTERVAL = 3000; | 
| 23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; | 23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; | 
| 24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; | 24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; | 
| 25 | 25 | 
| 26 /** Return position of node from parent. | 26 /** Return position of node from parent. | 
| 27  * @param {Node} node the node to find the position of. | 27  * @param {Node} node the node to find the position of. | 
| 28  * @return {number} One-based index like for :nth-child(), or 0 on error. | 28  * @return {number} One-based index like for :nth-child(), or 0 on error. | 
| 29  */ | 29  */ | 
| 30 function positionInParent(node) | 30 function positionInParent(node) | 
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 164   } | 164   } | 
| 165   return all ? subtree.querySelectorAll(selector) : | 165   return all ? subtree.querySelectorAll(selector) : | 
| 166     subtree.querySelector(selector); | 166     subtree.querySelector(selector); | 
| 167 } | 167 } | 
| 168 | 168 | 
| 169 function scopedQuerySelectorAll(subtree, selector) | 169 function scopedQuerySelectorAll(subtree, selector) | 
| 170 { | 170 { | 
| 171   return scopedQuerySelector(subtree, selector, true); | 171   return scopedQuerySelector(subtree, selector, true); | 
| 172 } | 172 } | 
| 173 | 173 | 
|  | 174 const regexpRegexp = /^\/(.*)\/([im]*)$/; | 
|  | 175 | 
|  | 176 /** | 
|  | 177  * Make a regular expression from a text argument. If it can be parsed as a | 
|  | 178  * regular expression, parse it and the flags. | 
|  | 179  * @param {string} text the text argument. | 
|  | 180  * @return {?RegExp} a RegExp object or null in case of error. | 
|  | 181  */ | 
|  | 182 function makeRegExpParameter(text) | 
|  | 183 { | 
|  | 184   let [, pattern, flags] = | 
|  | 185       regexpRegexp.exec(text) || [undefined, textToRegExp(text)]; | 
|  | 186 | 
|  | 187   try | 
|  | 188   { | 
|  | 189     return new RegExp(pattern, flags); | 
|  | 190   } | 
|  | 191   catch (e) | 
|  | 192   { | 
|  | 193   } | 
|  | 194   return null; | 
|  | 195 } | 
|  | 196 | 
| 174 function* evaluate(chain, index, prefix, subtree, styles) | 197 function* evaluate(chain, index, prefix, subtree, styles) | 
| 175 { | 198 { | 
| 176   if (index >= chain.length) | 199   if (index >= chain.length) | 
| 177   { | 200   { | 
| 178     yield prefix; | 201     yield prefix; | 
| 179     return; | 202     return; | 
| 180   } | 203   } | 
| 181   for (let [selector, element] of | 204   for (let [selector, element] of | 
| 182        chain[index].getSelectors(prefix, subtree, styles)) | 205        chain[index].getSelectors(prefix, subtree, styles)) | 
| 183   { | 206   { | 
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 256             yield element; | 279             yield element; | 
| 257         } | 280         } | 
| 258         yield null; | 281         yield null; | 
| 259       } | 282       } | 
| 260     } | 283     } | 
| 261   } | 284   } | 
| 262 }; | 285 }; | 
| 263 | 286 | 
| 264 function ContainsSelector(textContent) | 287 function ContainsSelector(textContent) | 
| 265 { | 288 { | 
| 266   this._text = textContent; | 289   this._regexp = makeRegExpParameter(textContent); | 
| 267 } | 290 } | 
| 268 | 291 | 
| 269 ContainsSelector.prototype = { | 292 ContainsSelector.prototype = { | 
| 270   requiresHiding: true, | 293   requiresHiding: true, | 
| 271 | 294 | 
| 272   *getSelectors(prefix, subtree, stylesheet) | 295   *getSelectors(prefix, subtree, stylesheet) | 
| 273   { | 296   { | 
| 274     for (let element of this.getElements(prefix, subtree, stylesheet)) | 297     for (let element of this.getElements(prefix, subtree, stylesheet)) | 
| 275       yield [makeSelector(element, ""), subtree]; | 298       yield [makeSelector(element, ""), subtree]; | 
| 276   }, | 299   }, | 
| 277 | 300 | 
| 278   *getElements(prefix, subtree, stylesheet) | 301   *getElements(prefix, subtree, stylesheet) | 
| 279   { | 302   { | 
| 280     let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 303     let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 
| 281         prefix + "*" : prefix; | 304         prefix + "*" : prefix; | 
| 282 | 305 | 
| 283     let elements = scopedQuerySelectorAll(subtree, actualPrefix); | 306     let elements = scopedQuerySelectorAll(subtree, actualPrefix); | 
| 284     if (elements) | 307     if (elements) | 
| 285     { | 308     { | 
| 286       for (let element of elements) | 309       for (let element of elements) | 
| 287       { | 310       { | 
| 288         if (element.textContent.includes(this._text)) | 311         if (this._regexp && this._regexp.test(element.textContent)) | 
| 289           yield element; | 312           yield element; | 
| 290         else | 313         else | 
| 291           yield null; | 314           yield null; | 
| 292       } | 315       } | 
| 293     } | 316     } | 
| 294   } | 317   } | 
| 295 }; | 318 }; | 
| 296 | 319 | 
| 297 function PropsSelector(propertyExpression) | 320 function PropsSelector(propertyExpression) | 
| 298 { | 321 { | 
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 646           characterData: true, | 669           characterData: true, | 
| 647           subtree: true | 670           subtree: true | 
| 648         } | 671         } | 
| 649       ); | 672       ); | 
| 650       this.document.addEventListener("load", this.onLoad.bind(this), true); | 673       this.document.addEventListener("load", this.onLoad.bind(this), true); | 
| 651     } | 674     } | 
| 652   } | 675   } | 
| 653 }; | 676 }; | 
| 654 | 677 | 
| 655 exports.ElemHideEmulation = ElemHideEmulation; | 678 exports.ElemHideEmulation = ElemHideEmulation; | 
| OLD | NEW | 
|---|