| 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 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 let priority = rule.style.getPropertyPriority(property); | 115 let priority = rule.style.getPropertyPriority(property); |
| 116 styles.push(`${property}: ${value}${priority ? " !" + priority : ""};`); | 116 styles.push(`${property}: ${value}${priority ? " !" + priority : ""};`); |
| 117 } | 117 } |
| 118 styles.sort(); | 118 styles.sort(); |
| 119 return { | 119 return { |
| 120 style: styles.join(" "), | 120 style: styles.join(" "), |
| 121 subSelectors: splitSelector(rule.selectorText) | 121 subSelectors: splitSelector(rule.selectorText) |
| 122 }; | 122 }; |
| 123 } | 123 } |
| 124 | 124 |
| 125 /** |
| 126 * Make a regular expresson from a text argument. |
| 127 * @param {string} text the text argument. |
| 128 * @param {?string} flag the regexp flag passed to the RegExp constructor. |
| 129 * @return {RegExp} a RegExp object. |
| 130 */ |
| 131 function makeRegExpParameter(text, flag) |
| 132 { |
| 133 let regexpString = null; |
| 134 if (text.length >= 2 && text[0] == "/" && |
| 135 text[text.length - 1] == "/") |
| 136 { |
| 137 regexpString = text.slice(1, -1) |
| 138 .replace("\\7B ", "{").replace("\\7D ", "}"); |
| 139 } |
| 140 else |
| 141 regexpString = filterToRegExp(text); |
| 142 |
| 143 return new RegExp(regexpString, flag); |
| 144 } |
| 145 |
| 125 function* evaluate(chain, index, prefix, subtree, styles) | 146 function* evaluate(chain, index, prefix, subtree, styles) |
| 126 { | 147 { |
| 127 if (index >= chain.length) | 148 if (index >= chain.length) |
| 128 { | 149 { |
| 129 yield prefix; | 150 yield prefix; |
| 130 return; | 151 return; |
| 131 } | 152 } |
| 132 for (let [selector, element] of | 153 for (let [selector, element] of |
| 133 chain[index].getSelectors(prefix, subtree, styles)) | 154 chain[index].getSelectors(prefix, subtree, styles)) |
| 134 { | 155 { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // :scope isn't supported on Edge, ignore error caused by it. | 238 // :scope isn't supported on Edge, ignore error caused by it. |
| 218 } | 239 } |
| 219 } | 240 } |
| 220 yield null; | 241 yield null; |
| 221 } | 242 } |
| 222 } | 243 } |
| 223 }; | 244 }; |
| 224 | 245 |
| 225 function ContainsSelector(textContent) | 246 function ContainsSelector(textContent) |
| 226 { | 247 { |
| 227 this._text = textContent; | 248 this._regexp = makeRegExpParameter(textContent); |
| 228 } | 249 } |
| 229 | 250 |
| 230 ContainsSelector.prototype = { | 251 ContainsSelector.prototype = { |
| 231 requiresHiding: true, | 252 requiresHiding: true, |
| 232 | 253 |
| 233 *getSelectors(prefix, subtree, stylesheet) | 254 *getSelectors(prefix, subtree, stylesheet) |
| 234 { | 255 { |
| 235 for (let element of this.getElements(prefix, subtree, stylesheet)) | 256 for (let element of this.getElements(prefix, subtree, stylesheet)) |
| 236 yield [makeSelector(element, ""), subtree]; | 257 yield [makeSelector(element, ""), subtree]; |
| 237 }, | 258 }, |
| 238 | 259 |
| 239 *getElements(prefix, subtree, stylesheet) | 260 *getElements(prefix, subtree, stylesheet) |
| 240 { | 261 { |
| 241 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 262 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
| 242 prefix + "*" : prefix; | 263 prefix + "*" : prefix; |
| 243 let elements = subtree.querySelectorAll(actualPrefix); | 264 let elements = subtree.querySelectorAll(actualPrefix); |
| 244 | 265 |
| 245 for (let element of elements) | 266 for (let element of elements) |
| 246 { | 267 { |
| 247 if (element.textContent.includes(this._text)) | 268 if (this._regexp && this._regexp.test(element.textContent)) |
| 248 yield element; | 269 yield element; |
| 249 else | 270 else |
| 250 yield null; | 271 yield null; |
| 251 } | 272 } |
| 252 } | 273 } |
| 253 }; | 274 }; |
| 254 | 275 |
| 255 function PropsSelector(propertyExpression) | 276 function PropsSelector(propertyExpression) |
| 256 { | 277 { |
| 257 let regexpString; | 278 this._regexp = makeRegExpParameter(propertyExpression, "i"); |
| 258 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | |
| 259 propertyExpression[propertyExpression.length - 1] == "/") | |
| 260 { | |
| 261 regexpString = propertyExpression.slice(1, -1) | |
| 262 .replace("\\7B ", "{").replace("\\7D ", "}"); | |
| 263 } | |
| 264 else | |
| 265 regexpString = filterToRegExp(propertyExpression); | |
| 266 | |
| 267 this._regexp = new RegExp(regexpString, "i"); | |
| 268 } | 279 } |
| 269 | 280 |
| 270 PropsSelector.prototype = { | 281 PropsSelector.prototype = { |
| 271 preferHideWithSelector: true, | 282 preferHideWithSelector: true, |
| 272 dependsOnStyles: true, | 283 dependsOnStyles: true, |
| 273 | 284 |
| 274 *findPropsSelectors(styles, prefix, regexp) | 285 *findPropsSelectors(styles, prefix, regexp) |
| 275 { | 286 { |
| 276 for (let style of styles) | 287 for (let style of styles) |
| 277 if (regexp.test(style.style)) | 288 if (regexp.test(style.style)) |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 characterData: true, | 615 characterData: true, |
| 605 subtree: true | 616 subtree: true |
| 606 } | 617 } |
| 607 ); | 618 ); |
| 608 this.document.addEventListener("load", this.onLoad.bind(this), true); | 619 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 609 } | 620 } |
| 610 } | 621 } |
| 611 }; | 622 }; |
| 612 | 623 |
| 613 exports.ElemHideEmulation = ElemHideEmulation; | 624 exports.ElemHideEmulation = ElemHideEmulation; |
| OLD | NEW |