| 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-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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 } | 79 } |
| 80 unconditionalSelectors = null; | 80 unconditionalSelectors = null; |
| 81 FilterNotifier.emit("elemhideupdate"); | 81 FilterNotifier.emit("elemhideupdate"); |
| 82 }, | 82 }, |
| 83 | 83 |
| 84 _addToFiltersByDomain(filter) | 84 _addToFiltersByDomain(filter) |
| 85 { | 85 { |
| 86 let domains = filter.domains || defaultDomains; | 86 let domains = filter.domains || defaultDomains; |
| 87 for (let [domain, isIncluded] of domains) | 87 for (let [domain, isIncluded] of domains) |
| 88 { | 88 { |
| 89 // There's no need to note that a filter is generically disabled. | |
| 90 if (!isIncluded && domain == "") | |
| 91 continue; | |
| 92 | |
| 89 let filters = filtersByDomain.get(domain); | 93 let filters = filtersByDomain.get(domain); |
| 90 if (!filters) | 94 if (!filters) |
| 91 filtersByDomain.set(domain, filters = new Map()); | 95 filtersByDomain.set(domain, filters = new Map()); |
| 92 filters.set(filter, isIncluded); | 96 filters.set(filter, isIncluded); |
|
Manish Jethani
2018/04/30 17:55:21
I think we should change this to:
if (domain ||
kzar
2018/05/01 16:13:59
Good point, you're right and I checked and this ap
| |
| 93 } | 97 } |
| 94 }, | 98 }, |
| 95 | 99 |
| 96 /** | 100 /** |
| 97 * Add a new element hiding filter | 101 * Add a new element hiding filter |
| 98 * @param {ElemHideBase} filter | 102 * @param {ElemHideBase} filter |
| 99 */ | 103 */ |
| 100 add(filter) | 104 add(filter) |
| 101 { | 105 { |
| 102 if (knownFilters.has(filter)) | 106 if (knownFilters.has(filter)) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 153 |
| 150 // Whitelisting filters | 154 // Whitelisting filters |
| 151 if (filter instanceof ElemHideException) | 155 if (filter instanceof ElemHideException) |
| 152 { | 156 { |
| 153 let list = exceptions.get(filter.selector); | 157 let list = exceptions.get(filter.selector); |
| 154 let index = list.indexOf(filter); | 158 let index = list.indexOf(filter); |
| 155 if (index >= 0) | 159 if (index >= 0) |
| 156 list.splice(index, 1); | 160 list.splice(index, 1); |
| 157 } | 161 } |
| 158 // Unconditially applied element hiding filters | 162 // Unconditially applied element hiding filters |
| 159 else if (filterBySelector.get(filter.selector) === filter) | 163 else if (filterBySelector.get(filter.selector) == filter) |
| 160 { | 164 { |
| 161 filterBySelector.delete(filter.selector); | 165 filterBySelector.delete(filter.selector); |
| 162 unconditionalSelectors = null; | 166 unconditionalSelectors = null; |
| 163 } | 167 } |
| 164 // Conditionally applied element hiding filters | 168 // Conditionally applied element hiding filters |
| 165 else | 169 else |
| 166 { | 170 { |
| 167 let domains = filter.domains || defaultDomains; | 171 let domains = filter.domains || defaultDomains; |
| 168 for (let domain of domains.keys()) | 172 for (let domain of domains.keys()) |
| 169 { | 173 { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 getSelectorsForDomain(domain, criteria) | 245 getSelectorsForDomain(domain, criteria) |
| 242 { | 246 { |
| 243 let selectors = []; | 247 let selectors = []; |
| 244 | 248 |
| 245 if (typeof criteria == "undefined") | 249 if (typeof criteria == "undefined") |
| 246 criteria = ElemHide.ALL_MATCHING; | 250 criteria = ElemHide.ALL_MATCHING; |
| 247 if (criteria < ElemHide.NO_UNCONDITIONAL) | 251 if (criteria < ElemHide.NO_UNCONDITIONAL) |
| 248 selectors = this.getUnconditionalSelectors(); | 252 selectors = this.getUnconditionalSelectors(); |
| 249 | 253 |
| 250 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); | 254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); |
| 251 let seenFilters = new Set(); | 255 let excluded = new Set(); |
| 252 let currentDomain = domain ? domain.toUpperCase() : ""; | 256 let currentDomain = domain ? domain.toUpperCase() : ""; |
| 257 | |
| 258 // This code is a performance hot-spot, which is why we've made certain | |
| 259 // micro-optimisations. Please be careful before making changes. | |
| 253 while (true) | 260 while (true) |
| 254 { | 261 { |
| 255 if (specificOnly && currentDomain == "") | 262 if (specificOnly && currentDomain == "") |
| 256 break; | 263 break; |
| 257 | 264 |
| 258 let filters = filtersByDomain.get(currentDomain); | 265 let filters = filtersByDomain.get(currentDomain); |
| 259 if (filters) | 266 if (filters) |
| 260 { | 267 { |
| 261 for (let [filter, isIncluded] of filters) | 268 for (let [filter, isIncluded] of filters) |
|
Manish Jethani
2018/04/30 17:55:21
So your comment about included vs excluded filters
kzar
2018/05/01 16:13:59
This is pretty much the same point you made on you
Manish Jethani
2018/05/02 12:28:11
Fair enough.
In that case, do you think it makes
Manish Jethani
2018/05/02 12:57:34
I just checked here and with just EasyList enabled
kzar
2018/05/02 16:45:38
You make some good points and I think on reflectio
| |
| 262 { | 269 { |
| 263 if (seenFilters.has(filter)) | 270 if (!isIncluded) |
| 264 continue; | 271 { |
| 265 seenFilters.add(filter); | 272 excluded.add(filter); |
| 266 | 273 } |
| 267 if (isIncluded && !this.getException(filter, domain)) | 274 else if ((excluded.size == 0 || !excluded.has(filter)) && |
| 275 !this.getException(filter, domain)) | |
| 276 { | |
| 268 selectors.push(filter.selector); | 277 selectors.push(filter.selector); |
| 278 } | |
| 269 } | 279 } |
| 270 } | 280 } |
| 271 | 281 |
| 272 if (currentDomain == "") | 282 if (currentDomain == "") |
|
Manish Jethani
2018/05/02 12:57:34
I'm wondering if we should update these checks:
kzar
2018/05/02 16:45:39
Well I think it's generally a good idea to check t
Manish Jethani
2018/05/02 18:11:40
OK, the Mozilla style guide, which we refer to, ad
kzar
2018/05/03 15:36:00
I prefer checking for an empty string specifically
Manish Jethani
2018/05/04 11:59:55
Acknowledged.
| |
| 273 break; | 283 break; |
| 274 | 284 |
| 275 let nextDot = currentDomain.indexOf("."); | 285 let nextDot = currentDomain.indexOf("."); |
| 276 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
| 277 } | 287 } |
| 278 | 288 |
| 279 return selectors; | 289 return selectors; |
| 280 } | 290 } |
| 281 }; | 291 }; |
| LEFT | RIGHT |