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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 | 153 |
154 // Whitelisting filters | 154 // Whitelisting filters |
155 if (filter instanceof ElemHideException) | 155 if (filter instanceof ElemHideException) |
156 { | 156 { |
157 let list = exceptions.get(filter.selector); | 157 let list = exceptions.get(filter.selector); |
158 let index = list.indexOf(filter); | 158 let index = list.indexOf(filter); |
159 if (index >= 0) | 159 if (index >= 0) |
160 list.splice(index, 1); | 160 list.splice(index, 1); |
161 } | 161 } |
162 // Unconditially applied element hiding filters | 162 // Unconditially applied element hiding filters |
163 else if (filterBySelector.get(filter.selector) === filter) | 163 else if (filterBySelector.get(filter.selector) == filter) |
164 { | 164 { |
165 filterBySelector.delete(filter.selector); | 165 filterBySelector.delete(filter.selector); |
166 unconditionalSelectors = null; | 166 unconditionalSelectors = null; |
167 } | 167 } |
168 // Conditionally applied element hiding filters | 168 // Conditionally applied element hiding filters |
169 else | 169 else |
170 { | 170 { |
171 let domains = filter.domains || defaultDomains; | 171 let domains = filter.domains || defaultDomains; |
172 for (let domain of domains.keys()) | 172 for (let domain of domains.keys()) |
173 { | 173 { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 getSelectorsForDomain(domain, criteria) | 245 getSelectorsForDomain(domain, criteria) |
246 { | 246 { |
247 let selectors = []; | 247 let selectors = []; |
248 | 248 |
249 if (typeof criteria == "undefined") | 249 if (typeof criteria == "undefined") |
250 criteria = ElemHide.ALL_MATCHING; | 250 criteria = ElemHide.ALL_MATCHING; |
251 if (criteria < ElemHide.NO_UNCONDITIONAL) | 251 if (criteria < ElemHide.NO_UNCONDITIONAL) |
252 selectors = this.getUnconditionalSelectors(); | 252 selectors = this.getUnconditionalSelectors(); |
253 | 253 |
254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); | 254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); |
255 let excludedFilters = new Set(); | 255 let excluded = new Set(); |
256 | |
257 let currentDomain = domain ? domain.toUpperCase() : ""; | 256 let currentDomain = domain ? domain.toUpperCase() : ""; |
258 let currentDomainIsGeneric = currentDomain == ""; | |
Manish Jethani
2018/05/02 18:11:40
Comparison with an empty string really should not
kzar
2018/05/03 15:36:00
OK, Done.
| |
259 | 257 |
260 // This code is a performance hot-spot, which is why we've made certain | 258 // This code is a performance hot-spot, which is why we've made certain |
261 // micro-optimisations. Please be careful before making changes. | 259 // micro-optimisations. Please be careful before making changes. |
262 while (true) | 260 while (true) |
263 { | 261 { |
264 if (specificOnly && currentDomainIsGeneric) | 262 if (specificOnly && currentDomain == "") |
265 break; | 263 break; |
266 | 264 |
267 let filters = filtersByDomain.get(currentDomain); | 265 let filters = filtersByDomain.get(currentDomain); |
268 if (filters) | 266 if (filters) |
269 { | 267 { |
270 for (let [filter, isIncluded] of filters) | 268 for (let [filter, isIncluded] of filters) |
271 { | 269 { |
272 if (excludedFilters.size > 0 && excludedFilters.has(filter)) | 270 if (!isIncluded) |
Manish Jethani
2018/05/02 18:11:40
We only need to do this check for included filters
kzar
2018/05/03 15:36:01
Good point, Done.
| |
273 continue; | |
274 | |
275 if (isIncluded) | |
276 { | 271 { |
277 if (!this.getException(filter, domain)) | 272 excluded.add(filter); |
278 selectors.push(filter.selector); | |
279 } | 273 } |
280 else if (!currentDomainIsGeneric) | 274 else if ((excluded.size == 0 || !excluded.has(filter)) && |
Manish Jethani
2018/05/02 18:11:40
currentDomain will always be non-empty if the filt
kzar
2018/05/03 15:36:00
OK, Done.
| |
281 excludedFilters.add(filter); | 275 !this.getException(filter, domain)) |
276 { | |
277 selectors.push(filter.selector); | |
278 } | |
282 } | 279 } |
283 } | 280 } |
284 | 281 |
285 if (currentDomainIsGeneric) | 282 if (currentDomain == "") |
286 break; | 283 break; |
287 | 284 |
288 let nextDot = currentDomain.indexOf("."); | 285 let nextDot = currentDomain.indexOf("."); |
289 if (nextDot == -1) | 286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
290 { | |
291 currentDomain = ""; | |
292 currentDomainIsGeneric = true; | |
293 } | |
294 else | |
295 currentDomain = currentDomain.substr(nextDot + 1); | |
296 } | 287 } |
297 | 288 |
298 return selectors; | 289 return selectors; |
299 } | 290 } |
300 }; | 291 }; |
LEFT | RIGHT |