Left: | ||
Right: |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 */ | 56 */ |
57 let knownFilters = new Set(); | 57 let knownFilters = new Set(); |
58 | 58 |
59 /** | 59 /** |
60 * Lookup table, lists of element hiding exceptions by selector | 60 * Lookup table, lists of element hiding exceptions by selector |
61 * @type {Map.<string,Filter>} | 61 * @type {Map.<string,Filter>} |
62 */ | 62 */ |
63 let exceptions = new Map(); | 63 let exceptions = new Map(); |
64 | 64 |
65 /** | 65 /** |
66 * Returns a list of selectors that apply on each website unconditionally. | |
kzar
2018/05/10 10:59:49
Please could you also remove this unrelated change
Manish Jethani
2018/05/11 04:07:10
Well if we're going to keep the function available
kzar
2018/05/11 11:23:43
Gotya, OK that makes sense.
This LGTM then, I'd p
| |
67 * @returns {string[]} | |
68 */ | |
69 function getUnconditionalSelectors() | |
70 { | |
71 if (!unconditionalSelectors) | |
72 unconditionalSelectors = [...filterBySelector.keys()]; | |
73 | |
74 return unconditionalSelectors; | |
75 } | |
76 | |
77 /** | |
66 * Container for element hiding filters | 78 * Container for element hiding filters |
67 * @class | 79 * @class |
68 */ | 80 */ |
69 let ElemHide = exports.ElemHide = { | 81 let ElemHide = exports.ElemHide = { |
70 /** | 82 /** |
71 * Removes all known filters | 83 * Removes all known filters |
72 */ | 84 */ |
73 clear() | 85 clear() |
74 { | 86 { |
75 for (let collection of [filtersByDomain, filterBySelector, | 87 for (let collection of [filtersByDomain, filterBySelector, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 for (let i = list.length - 1; i >= 0; i--) | 209 for (let i = list.length - 1; i >= 0; i--) |
198 { | 210 { |
199 if (list[i].isActiveOnDomain(docDomain)) | 211 if (list[i].isActiveOnDomain(docDomain)) |
200 return list[i]; | 212 return list[i]; |
201 } | 213 } |
202 | 214 |
203 return null; | 215 return null; |
204 }, | 216 }, |
205 | 217 |
206 /** | 218 /** |
207 * Returns a list of selectors that apply on each website unconditionally. | |
208 * @returns {string[]} | |
209 */ | |
210 getUnconditionalSelectors() | |
211 { | |
212 if (!unconditionalSelectors) | |
213 unconditionalSelectors = [...filterBySelector.keys()]; | |
214 return unconditionalSelectors.slice(); | |
215 }, | |
216 | |
217 /** | |
218 * Constant used by getSelectorsForDomain to return all selectors applying to | 219 * Constant used by getSelectorsForDomain to return all selectors applying to |
219 * a particular hostname. | 220 * a particular hostname. |
220 */ | 221 */ |
221 ALL_MATCHING: 0, | 222 ALL_MATCHING: 0, |
222 | 223 |
223 /** | 224 /** |
224 * Constant used by getSelectorsForDomain to exclude selectors which apply to | 225 * Constant used by getSelectorsForDomain to exclude selectors which apply to |
225 * all websites without exception. | 226 * all websites without exception. |
226 */ | 227 */ |
227 NO_UNCONDITIONAL: 1, | 228 NO_UNCONDITIONAL: 1, |
(...skipping 13 matching lines...) Expand all Loading... | |
241 * ElemHide.SPECIFIC_ONLY. | 242 * ElemHide.SPECIFIC_ONLY. |
242 * @returns {string[]} | 243 * @returns {string[]} |
243 * List of selectors. | 244 * List of selectors. |
244 */ | 245 */ |
245 getSelectorsForDomain(domain, criteria) | 246 getSelectorsForDomain(domain, criteria) |
246 { | 247 { |
247 let selectors = []; | 248 let selectors = []; |
248 | 249 |
249 if (typeof criteria == "undefined") | 250 if (typeof criteria == "undefined") |
250 criteria = ElemHide.ALL_MATCHING; | 251 criteria = ElemHide.ALL_MATCHING; |
251 if (criteria < ElemHide.NO_UNCONDITIONAL) | |
252 selectors = this.getUnconditionalSelectors(); | |
253 | 252 |
254 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); | 253 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); |
255 let excluded = new Set(); | 254 let excluded = new Set(); |
256 let currentDomain = domain ? domain.toUpperCase() : ""; | 255 let currentDomain = domain ? domain.toUpperCase() : ""; |
257 | 256 |
258 // This code is a performance hot-spot, which is why we've made certain | 257 // This code is a performance hot-spot, which is why we've made certain |
259 // micro-optimisations. Please be careful before making changes. | 258 // micro-optimisations. Please be careful before making changes. |
260 while (true) | 259 while (true) |
261 { | 260 { |
262 if (specificOnly && currentDomain == "") | 261 if (specificOnly && currentDomain == "") |
(...skipping 16 matching lines...) Expand all Loading... | |
279 } | 278 } |
280 } | 279 } |
281 | 280 |
282 if (currentDomain == "") | 281 if (currentDomain == "") |
283 break; | 282 break; |
284 | 283 |
285 let nextDot = currentDomain.indexOf("."); | 284 let nextDot = currentDomain.indexOf("."); |
286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 285 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
287 } | 286 } |
288 | 287 |
288 if (criteria < ElemHide.NO_UNCONDITIONAL) | |
289 selectors = getUnconditionalSelectors().concat(selectors); | |
290 | |
289 return selectors; | 291 return selectors; |
290 } | 292 } |
291 }; | 293 }; |
OLD | NEW |