| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 var filtersByDomain = Object.create(null); | 46 var filtersByDomain = Object.create(null); |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Indicates whether we are using (and maintaining) the filtersByDomain lookup. | 49 * Indicates whether we are using (and maintaining) the filtersByDomain lookup. |
| 50 * (Will be false for Firefox) | 50 * (Will be false for Firefox) |
| 51 * @type Boolean | 51 * @type Boolean |
| 52 */ | 52 */ |
| 53 var usingFiltersByDomain = !("nsIStyleSheetService" in Ci); | 53 var usingFiltersByDomain = !("nsIStyleSheetService" in Ci); |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Object to be used instead when a filter has a blank domains property. | |
| 57 */ | |
| 58 var defaultDomains = Object.create(null); | |
| 59 defaultDomains[""] = true; | |
| 60 | |
| 61 /** | |
| 56 * Lookup table, keys are known element hiding exceptions | 62 * Lookup table, keys are known element hiding exceptions |
| 57 * @type Object | 63 * @type Object |
| 58 */ | 64 */ |
| 59 var knownExceptions = Object.create(null); | 65 var knownExceptions = Object.create(null); |
| 60 | 66 |
| 61 /** | 67 /** |
| 62 * Lookup table, lists of element hiding exceptions by selector | 68 * Lookup table, lists of element hiding exceptions by selector |
| 63 * @type Object | 69 * @type Object |
| 64 */ | 70 */ |
| 65 var exceptions = Object.create(null); | 71 var exceptions = Object.create(null); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 let key; | 150 let key; |
| 145 do { | 151 do { |
| 146 key = Math.random().toFixed(15).substr(5); | 152 key = Math.random().toFixed(15).substr(5); |
| 147 } while (key in filterByKey); | 153 } while (key in filterByKey); |
| 148 | 154 |
| 149 filterByKey[key] = filter; | 155 filterByKey[key] = filter; |
| 150 keyByFilter[filter.text] = key; | 156 keyByFilter[filter.text] = key; |
| 151 | 157 |
| 152 if (usingFiltersByDomain) | 158 if (usingFiltersByDomain) |
| 153 { | 159 { |
| 154 let domainMatches = filter.domains || {"": true}; | 160 let domainMatches = filter.domains || defaultDomains; |
| 155 for (let domain in domainMatches) | 161 for (let domain in domainMatches) |
| 156 { | 162 { |
| 157 domain = domain.toUpperCase(); | 163 let filters = filtersByDomain[domain]; |
| 158 if (!(domain in filtersByDomain)) | 164 if (!filters) |
|
Sebastian Noack
2016/05/17 09:47:49
I think we should cache the lookup here:
let fi
kzar
2016/05/17 10:05:45
Done.
| |
| 159 filtersByDomain[domain] = Object.create(null); | 165 filters = filtersByDomain[domain] = Object.create(null); |
| 160 filtersByDomain[domain][filter.text] = domainMatches[domain] && filter ; | 166 |
| 167 if (domainMatches[domain]) | |
| 168 filters[filter.text] = filter; | |
| 169 else | |
| 170 filters[filter.text] = false; | |
| 161 } | 171 } |
| 162 } | 172 } |
| 163 | 173 |
| 164 ElemHide.isDirty = true; | 174 ElemHide.isDirty = true; |
| 165 } | 175 } |
| 166 }, | 176 }, |
| 167 | 177 |
| 168 /** | 178 /** |
| 169 * Removes an element hiding filter | 179 * Removes an element hiding filter |
| 170 * @param {ElemHideFilter} filter | 180 * @param {ElemHideFilter} filter |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 while (true) | 420 while (true) |
| 411 { | 421 { |
| 412 if (specificOnly && currentDomain == "") | 422 if (specificOnly && currentDomain == "") |
| 413 break; | 423 break; |
| 414 | 424 |
| 415 let filters = filtersByDomain[currentDomain]; | 425 let filters = filtersByDomain[currentDomain]; |
| 416 if (filters) | 426 if (filters) |
| 417 { | 427 { |
| 418 for (let filterText in filters) | 428 for (let filterText in filters) |
| 419 { | 429 { |
| 420 if (filterText in seenFilters) | 430 if (filterText in seenFilters) |
|
Sebastian Noack
2016/05/17 09:47:49
Is this some kind of micro optimization or an atte
kzar
2016/05/17 10:05:45
There's a comment in the old codereview about how
| |
| 421 continue; | 431 continue; |
| 422 seenFilters[filterText] = true; | 432 seenFilters[filterText] = true; |
| 423 | 433 |
| 424 let filter = filters[filterText]; | 434 let filter = filters[filterText]; |
| 425 if (filter && !this.getException(filter, domain)) | 435 if (filter && !this.getException(filter, domain)) |
|
Sebastian Noack
2016/05/17 09:47:49
I still have a hard time to understand how/whether
kzar
2016/05/17 10:05:45
For ~example.com##div there should be two entries
| |
| 426 selectors.push(filter.selector); | 436 selectors.push(filter.selector); |
| 427 } | 437 } |
| 428 } | 438 } |
| 429 | 439 |
| 430 if (currentDomain == "") | 440 if (currentDomain == "") |
| 431 break; | 441 break; |
| 432 | 442 |
| 433 let nextDot = currentDomain.indexOf("."); | 443 let nextDot = currentDomain.indexOf("."); |
| 434 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 444 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
| 435 } | 445 } |
| 436 | 446 |
| 437 return selectors; | 447 return selectors; |
| 438 } | 448 } |
| 439 }; | 449 }; |
| LEFT | RIGHT |