| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Lookup table, keys of the filters by filter text | 34 * Lookup table, keys of the filters by filter text |
| 35 * @type {Object} | 35 * @type {Object} |
| 36 */ | 36 */ |
| 37 let keyByFilter = Object.create(null); | 37 let keyByFilter = Object.create(null); |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Nested lookup table, filter (or false if inactive) by filter key by domain. | 40 * Nested lookup table, filter (or false if inactive) by filter key by domain. |
| 41 * (Only contains filters that aren't unconditionally matched for all domains.) | 41 * (Only contains filters that aren't unconditionally matched for all domains.) |
| 42 * @type {Object} | 42 * @type {Map.<string,Object>} |
| 43 */ | 43 */ |
| 44 let filtersByDomain = Object.create(null); | 44 let filtersByDomain = new Map(); |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Lookup table, filter key by selector. (Only used for selectors that are | 47 * Lookup table, filter key by selector. (Only used for selectors that are |
| 48 * unconditionally matched for all domains.) | 48 * unconditionally matched for all domains.) |
| 49 */ | 49 */ |
| 50 let filterKeyBySelector = Object.create(null); | 50 let filterKeyBySelector = Object.create(null); |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * This array caches the keys of filterKeyBySelector table (selectors which | 53 * This array caches the keys of filterKeyBySelector table (selectors which |
| 54 * unconditionally apply on all domains). It will be null if the cache needs to | 54 * unconditionally apply on all domains). It will be null if the cache needs to |
| (...skipping 30 matching lines...) Expand all Loading... |
| 85 * @class | 85 * @class |
| 86 */ | 86 */ |
| 87 let ElemHide = exports.ElemHide = { | 87 let ElemHide = exports.ElemHide = { |
| 88 /** | 88 /** |
| 89 * Removes all known filters | 89 * Removes all known filters |
| 90 */ | 90 */ |
| 91 clear() | 91 clear() |
| 92 { | 92 { |
| 93 filterByKey = []; | 93 filterByKey = []; |
| 94 keyByFilter = Object.create(null); | 94 keyByFilter = Object.create(null); |
| 95 filtersByDomain = Object.create(null); | 95 filtersByDomain = new Map(); |
| 96 filterKeyBySelector = Object.create(null); | 96 filterKeyBySelector = Object.create(null); |
| 97 unconditionalSelectors = unconditionalFilterKeys = null; | 97 unconditionalSelectors = unconditionalFilterKeys = null; |
| 98 knownExceptions = Object.create(null); | 98 knownExceptions = Object.create(null); |
| 99 exceptions = Object.create(null); | 99 exceptions = Object.create(null); |
| 100 FilterNotifier.emit("elemhideupdate"); | 100 FilterNotifier.emit("elemhideupdate"); |
| 101 }, | 101 }, |
| 102 | 102 |
| 103 _addToFiltersByDomain(key, filter) | 103 _addToFiltersByDomain(key, filter) |
| 104 { | 104 { |
| 105 let domains = filter.domains || defaultDomains; | 105 let domains = filter.domains || defaultDomains; |
| 106 for (let [domain, isIncluded] of domains) | 106 for (let [domain, isIncluded] of domains) |
| 107 { | 107 { |
| 108 let filters = filtersByDomain[domain]; | 108 let filters = filtersByDomain.get(domain); |
| 109 if (!filters) | 109 if (!filters) |
| 110 filters = filtersByDomain[domain] = Object.create(null); | 110 filtersByDomain.set(domain, filters = Object.create(null)); |
| 111 | 111 |
| 112 if (isIncluded) | 112 if (isIncluded) |
| 113 filters[key] = filter; | 113 filters[key] = filter; |
| 114 else | 114 else |
| 115 filters[key] = false; | 115 filters[key] = false; |
| 116 } | 116 } |
| 117 }, | 117 }, |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * Add a new element hiding filter | 120 * Add a new element hiding filter |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 delete filterKeyBySelector[filter.selector]; | 176 delete filterKeyBySelector[filter.selector]; |
| 177 unconditionalSelectors = unconditionalFilterKeys = null; | 177 unconditionalSelectors = unconditionalFilterKeys = null; |
| 178 return; | 178 return; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // We haven't found this filter in unconditional filters, look in | 181 // We haven't found this filter in unconditional filters, look in |
| 182 // filtersByDomain. | 182 // filtersByDomain. |
| 183 let domains = filter.domains || defaultDomains; | 183 let domains = filter.domains || defaultDomains; |
| 184 for (let domain of domains.keys()) | 184 for (let domain of domains.keys()) |
| 185 { | 185 { |
| 186 let filters = filtersByDomain[domain]; | 186 let filters = filtersByDomain.get(domain); |
| 187 if (filters) | 187 if (filters) |
| 188 delete filters[key]; | 188 delete filters[key]; |
| 189 } | 189 } |
| 190 }, | 190 }, |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * Removes an element hiding filter | 193 * Removes an element hiding filter |
| 194 * @param {ElemHideFilter} filter | 194 * @param {ElemHideFilter} filter |
| 195 */ | 195 */ |
| 196 remove(filter) | 196 remove(filter) |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 355 } |
| 356 | 356 |
| 357 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); | 357 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); |
| 358 let seenFilters = Object.create(null); | 358 let seenFilters = Object.create(null); |
| 359 let currentDomain = domain ? domain.toUpperCase() : ""; | 359 let currentDomain = domain ? domain.toUpperCase() : ""; |
| 360 while (true) | 360 while (true) |
| 361 { | 361 { |
| 362 if (specificOnly && currentDomain == "") | 362 if (specificOnly && currentDomain == "") |
| 363 break; | 363 break; |
| 364 | 364 |
| 365 let filters = filtersByDomain[currentDomain]; | 365 let filters = filtersByDomain.get(currentDomain); |
| 366 if (filters) | 366 if (filters) |
| 367 { | 367 { |
| 368 for (let filterKey in filters) | 368 for (let filterKey in filters) |
| 369 { | 369 { |
| 370 if (filterKey in seenFilters) | 370 if (filterKey in seenFilters) |
| 371 continue; | 371 continue; |
| 372 seenFilters[filterKey] = true; | 372 seenFilters[filterKey] = true; |
| 373 | 373 |
| 374 let filter = filters[filterKey]; | 374 let filter = filters[filterKey]; |
| 375 if (filter && !this.getException(filter, domain)) | 375 if (filter && !this.getException(filter, domain)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 386 | 386 |
| 387 let nextDot = currentDomain.indexOf("."); | 387 let nextDot = currentDomain.indexOf("."); |
| 388 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 388 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
| 389 } | 389 } |
| 390 | 390 |
| 391 if (provideFilterKeys) | 391 if (provideFilterKeys) |
| 392 return [selectors, filterKeys]; | 392 return [selectors, filterKeys]; |
| 393 return selectors; | 393 return selectors; |
| 394 } | 394 } |
| 395 }; | 395 }; |
| OLD | NEW |