| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 /** | 20 /** |
| 21 * @fileOverview Element hiding implementation. | 21 * @fileOverview Element hiding implementation. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 let {Utils} = require("utils"); | 24 const {ElemHideException} = require("filterClasses"); |
| 25 let {ElemHideException} = require("filterClasses"); | 25 const {FilterNotifier} = require("filterNotifier"); |
| 26 let {FilterNotifier} = require("filterNotifier"); | |
| 27 | 26 |
| 28 /** | 27 /** |
| 29 * Lookup table, filters by their associated key | 28 * Lookup table, filters by their associated key |
| 30 * @type {Object} | 29 * @type {Object} |
| 31 */ | 30 */ |
| 32 let filterByKey = []; | 31 let filterByKey = []; |
| 33 | 32 |
| 34 /** | 33 /** |
| 35 * Lookup table, keys of the filters by filter text | 34 * Lookup table, keys of the filters by filter text |
| 36 * @type {Object} | 35 * @type {Object} |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 { | 238 { |
| 240 if (list[i].isActiveOnDomain(docDomain)) | 239 if (list[i].isActiveOnDomain(docDomain)) |
| 241 return list[i]; | 240 return list[i]; |
| 242 } | 241 } |
| 243 | 242 |
| 244 return null; | 243 return null; |
| 245 }, | 244 }, |
| 246 | 245 |
| 247 /** | 246 /** |
| 248 * Retrieves an element hiding filter by the corresponding protocol key | 247 * Retrieves an element hiding filter by the corresponding protocol key |
| 249 * @param {Number} key | 248 * @param {number} key |
|
Sebastian Noack
2017/02/21 09:19:30
It's "number" (lowercase), same everywhere else.
kzar
2017/02/21 10:37:00
Done.
| |
| 250 * @return {Filter} | 249 * @return {Filter} |
| 251 */ | 250 */ |
| 252 getFilterByKey(key) | 251 getFilterByKey(key) |
| 253 { | 252 { |
| 254 return (key in filterByKey ? filterByKey[key] : null); | 253 return (key in filterByKey ? filterByKey[key] : null); |
| 255 }, | 254 }, |
| 256 | 255 |
| 257 /** | 256 /** |
| 258 * Returns a list of all selectors as a nested map. On first level, the keys | 257 * Returns a list of all selectors as a nested map. On first level, the keys |
| 259 * are all values of `ElemHideBase.selectorDomain` (domains on which these | 258 * are all values of `ElemHideBase.selectorDomain` (domains on which these |
| 260 * selectors should apply, ignoring exceptions). The values are maps again, | 259 * selectors should apply, ignoring exceptions). The values are maps again, |
| 261 * with the keys being selectors and values the corresponding filter keys. | 260 * with the keys being selectors and values the corresponding filter keys. |
| 262 * @returns {Map.<String,Map<String,String>>} | 261 * @returns {Map.<String,Map<String,String>>} |
| 263 */ | 262 */ |
| 264 getSelectors() | 263 getSelectors() |
| 265 { | 264 { |
| 266 let domains = new Map(); | 265 let domains = new Map(); |
| 267 for (let key in filterByKey) | 266 for (let key in filterByKey) |
| 268 { | 267 { |
| 269 let filter = filterByKey[key]; | 268 let filter = filterByKey[key]; |
| 270 let {selector} = filter; | 269 if (!filter.selector) |
| 271 if (!selector) | |
| 272 continue; | 270 continue; |
| 273 | 271 |
| 274 let domain = filter.selectorDomain || ""; | 272 let domain = filter.selectorDomain || ""; |
| 275 | 273 |
| 276 if (!domains.has(domain)) | 274 if (!domains.has(domain)) |
| 277 domains.set(domain, new Map()); | 275 domains.set(domain, new Map()); |
| 278 domains.get(domain).set(selector, key); | 276 domains.get(domain).set(filter.selector, key); |
| 279 } | 277 } |
| 280 | 278 |
| 281 return domains; | 279 return domains; |
| 282 }, | 280 }, |
| 283 | 281 |
| 284 /** | 282 /** |
| 285 * Returns a list of selectors that apply on each website unconditionally. | 283 * Returns a list of selectors that apply on each website unconditionally. |
| 286 * @returns {string[]} | 284 * @returns {string[]} |
| 287 */ | 285 */ |
| 288 getUnconditionalSelectors() | 286 getUnconditionalSelectors() |
| 289 { | 287 { |
| 290 if (!unconditionalSelectors) | 288 if (!unconditionalSelectors) |
| 291 unconditionalSelectors = Object.keys(filterKeyBySelector); | 289 unconditionalSelectors = Object.keys(filterKeyBySelector); |
| 292 return unconditionalSelectors.slice(); | 290 return unconditionalSelectors.slice(); |
| 293 }, | 291 }, |
| 294 | 292 |
| 295 /** | 293 /** |
| 296 * Returns a list of filter keys for selectors which apply to all websites | 294 * Returns a list of filter keys for selectors which apply to all websites |
| 297 * without exception. | 295 * without exception. |
| 298 * @returns {Number[]} | 296 * @returns {number[]} |
| 299 */ | 297 */ |
| 300 getUnconditionalFilterKeys() | 298 getUnconditionalFilterKeys() |
| 301 { | 299 { |
| 302 if (!unconditionalFilterKeys) | 300 if (!unconditionalFilterKeys) |
| 303 { | 301 { |
| 304 let selectors = this.getUnconditionalSelectors(); | 302 let selectors = this.getUnconditionalSelectors(); |
| 305 unconditionalFilterKeys = []; | 303 unconditionalFilterKeys = []; |
| 306 for (let selector of selectors) | 304 for (let selector of selectors) |
| 307 unconditionalFilterKeys.push(filterKeyBySelector[selector]); | 305 unconditionalFilterKeys.push(filterKeyBySelector[selector]); |
| 308 } | 306 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 326 * Constant used by getSelectorsForDomain to return only selectors for filters | 324 * Constant used by getSelectorsForDomain to return only selectors for filters |
| 327 * which specifically match the given host name. | 325 * which specifically match the given host name. |
| 328 */ | 326 */ |
| 329 SPECIFIC_ONLY: 2, | 327 SPECIFIC_ONLY: 2, |
| 330 | 328 |
| 331 /** | 329 /** |
| 332 * Determines from the current filter list which selectors should be applied | 330 * Determines from the current filter list which selectors should be applied |
| 333 * on a particular host name. Optionally returns the corresponding filter | 331 * on a particular host name. Optionally returns the corresponding filter |
| 334 * keys. | 332 * keys. |
| 335 * @param {string} domain | 333 * @param {string} domain |
| 336 * @param {Number} [criteria] | 334 * @param {number} [criteria] |
| 337 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or | 335 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or |
| 338 * ElemHide.SPECIFIC_ONLY. | 336 * ElemHide.SPECIFIC_ONLY. |
| 339 * @param {boolean} [provideFilterKeys] | 337 * @param {boolean} [provideFilterKeys] |
| 340 * If true, the function will return a list of corresponding filter keys in | 338 * If true, the function will return a list of corresponding filter keys in |
| 341 * addition to selectors. | 339 * addition to selectors. |
| 342 * @returns {string[]|Array.<string[]>} | 340 * @returns {string[]|Array.<string[]>} |
| 343 * List of selectors or an array with two elements (list of selectors and | 341 * List of selectors or an array with two elements (list of selectors and |
| 344 * list of corresponding keys) if provideFilterKeys is true. | 342 * list of corresponding keys) if provideFilterKeys is true. |
| 345 */ | 343 */ |
| 346 getSelectorsForDomain(domain, criteria, provideFilterKeys) | 344 getSelectorsForDomain(domain, criteria, provideFilterKeys) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 | 387 |
| 390 let nextDot = currentDomain.indexOf("."); | 388 let nextDot = currentDomain.indexOf("."); |
| 391 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 389 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
| 392 } | 390 } |
| 393 | 391 |
| 394 if (provideFilterKeys) | 392 if (provideFilterKeys) |
| 395 return [selectors, filterKeys]; | 393 return [selectors, filterKeys]; |
| 396 return selectors; | 394 return selectors; |
| 397 } | 395 } |
| 398 }; | 396 }; |
| LEFT | RIGHT |