 Issue 29562595:
  Issue 2824 - Only consider ads subscriptions in chooseFilterSubscription  (Closed)
    
  
    Issue 29562595:
  Issue 2824 - Only consider ads subscriptions in chooseFilterSubscription  (Closed) 
  | 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 | 74 | 
| 75 if (subscription instanceof SpecialSubscription && | 75 if (subscription instanceof SpecialSubscription && | 
| 76 subscription.filters.length > 0) | 76 subscription.filters.length > 0) | 
| 77 return false; | 77 return false; | 
| 78 } | 78 } | 
| 79 | 79 | 
| 80 return true; | 80 return true; | 
| 81 } | 81 } | 
| 82 | 82 | 
| 83 /** | 83 /** | 
| 84 * Returns the default filter subscriptions to add. | 84 * Finds the element for the default ad blocking filter subscription based | 
| 
Sebastian Noack
2017/10/03 00:24:40
I wouldn't insist on adding comments for functions
 
wspee
2017/10/03 09:26:54
Done.
 | |
| 85 * on the user's locale. | |
| 85 * | 86 * | 
| 86 * @param {HTMLCollection} subscriptions | 87 * @param {HTMLCollection} subscriptions | 
| 87 * @return {Element} | 88 * @return {Element} | 
| 88 */ | 89 */ | 
| 89 function chooseFilterSubscription(subscriptions) | 90 function chooseFilterSubscription(subscriptions) | 
| 90 { | 91 { | 
| 91 let selectedItem = null; | 92 let selectedItem = null; | 
| 92 let selectedPrefix = null; | 93 let selectedPrefix = null; | 
| 93 let matchCount = 0; | 94 let matchCount = 0; | 
| 94 for (let subscription of subscriptions) | 95 for (let subscription of subscriptions) | 
| 95 { | 96 { | 
| 96 if (!selectedItem) | 97 if (!selectedItem) | 
| 97 selectedItem = subscription; | 98 selectedItem = subscription; | 
| 98 | 99 | 
| 99 let prefix = Utils.checkLocalePrefixMatch( | 100 let prefixes = subscription.getAttribute("prefixes"); | 
| 
Sebastian Noack
2017/10/03 00:24:40
Since this seems to be the only call to that funct
 
wspee
2017/10/03 09:26:55
Done.
 | |
| 100 subscription.getAttribute("prefixes") | 101 let prefix = prefixes && prefixes.split(",").find( | 
| 102 lang => new RegExp("^" + lang + "\\b").test(Utils.appLocale) | |
| 101 ); | 103 ); | 
| 102 | 104 | 
| 103 let subscriptionType = subscription.getAttribute("type"); | 105 let subscriptionType = subscription.getAttribute("type"); | 
| 104 if (subscriptionType != "ads") | 106 | 
| 
Sebastian Noack
2017/10/03 00:24:40
This could be combined with the check below:
  if
 
wspee
2017/10/03 09:26:54
Done.
 | |
| 105 { | 107 if (prefix && subscriptionType == "ads") | 
| 106 continue; | |
| 107 } | |
| 108 | |
| 109 if (prefix) | |
| 110 { | 108 { | 
| 111 if (!selectedPrefix || selectedPrefix.length < prefix.length) | 109 if (!selectedPrefix || selectedPrefix.length < prefix.length) | 
| 112 { | 110 { | 
| 113 selectedItem = subscription; | 111 selectedItem = subscription; | 
| 114 selectedPrefix = prefix; | 112 selectedPrefix = prefix; | 
| 115 matchCount = 1; | 113 matchCount = 1; | 
| 116 } | 114 } | 
| 117 else if (selectedPrefix && selectedPrefix.length == prefix.length) | 115 else if (selectedPrefix && selectedPrefix.length == prefix.length) | 
| 118 { | 116 { | 
| 119 matchCount++; | 117 matchCount++; | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 * Sets a callback that is called with an array of subscriptions to be added | 228 * Sets a callback that is called with an array of subscriptions to be added | 
| 231 * during initialization. The callback must return an array of subscriptions | 229 * during initialization. The callback must return an array of subscriptions | 
| 232 * that will effectively be added. | 230 * that will effectively be added. | 
| 233 * | 231 * | 
| 234 * @param {function} callback | 232 * @param {function} callback | 
| 235 */ | 233 */ | 
| 236 exports.setSubscriptionsCallback = callback => | 234 exports.setSubscriptionsCallback = callback => | 
| 237 { | 235 { | 
| 238 subscriptionsCallback = callback; | 236 subscriptionsCallback = callback; | 
| 239 }; | 237 }; | 
| LEFT | RIGHT |