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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 if (!unconditionalSelectors) | 94 if (!unconditionalSelectors) |
95 unconditionalSelectors = [...filterBySelector.keys()]; | 95 unconditionalSelectors = [...filterBySelector.keys()]; |
96 | 96 |
97 return unconditionalSelectors; | 97 return unconditionalSelectors; |
98 } | 98 } |
99 | 99 |
100 /** | 100 /** |
101 * Container for element hiding filters | 101 * Container for element hiding filters |
102 * @class | 102 * @class |
103 */ | 103 */ |
104 let ElemHide = exports.ElemHide = { | 104 exports.ElemHide = { |
105 /** | 105 /** |
106 * Removes all known filters | 106 * Removes all known filters |
107 */ | 107 */ |
108 clear() | 108 clear() |
109 { | 109 { |
110 for (let collection of [filtersByDomain, filterBySelector, | 110 for (let collection of [filtersByDomain, filterBySelector, |
111 knownFilters, exceptions]) | 111 knownFilters, exceptions]) |
112 { | 112 { |
113 collection.clear(); | 113 collection.clear(); |
114 } | 114 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 for (let i = list.length - 1; i >= 0; i--) | 216 for (let i = list.length - 1; i >= 0; i--) |
217 { | 217 { |
218 if (list[i].isActiveOnDomain(docDomain)) | 218 if (list[i].isActiveOnDomain(docDomain)) |
219 return list[i]; | 219 return list[i]; |
220 } | 220 } |
221 | 221 |
222 return null; | 222 return null; |
223 }, | 223 }, |
224 | 224 |
225 /** | 225 /** |
226 * Constant used by getSelectorsForDomain to return all selectors applying to | |
227 * a particular hostname. | |
228 * @type {number} | |
229 * @const | |
230 */ | |
231 ALL_MATCHING: 0, | |
232 | |
233 /** | |
234 * Constant used by getSelectorsForDomain to exclude selectors which apply to | |
235 * all websites without exception. | |
236 * @type {number} | |
237 * @const | |
238 */ | |
239 NO_UNCONDITIONAL: 1, | |
240 | |
241 /** | |
242 * Constant used by getSelectorsForDomain to return only selectors for filters | |
243 * which specifically match the given host name. | |
244 * @type {number} | |
245 * @const | |
246 */ | |
247 SPECIFIC_ONLY: 2, | |
248 | |
249 /** | |
250 * Determines from the current filter list which selectors should be applied | 226 * Determines from the current filter list which selectors should be applied |
251 * on a particular host name. | 227 * on a particular host name. |
252 * @param {string} domain | 228 * @param {string} domain |
253 * @param {number} [criteria] | 229 * @param {boolean} [specificOnly] true if generic filters should not apply. |
254 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or | 230 * @returns {string[]} List of selectors. |
255 * ElemHide.SPECIFIC_ONLY. | |
256 * @returns {string[]} | |
257 * List of selectors. | |
258 */ | 231 */ |
259 getSelectorsForDomain(domain, criteria = ElemHide.ALL_MATCHING) | 232 getSelectorsForDomain(domain, specificOnly = false) |
260 { | 233 { |
261 let selectors = []; | 234 let selectors = []; |
262 | 235 |
263 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); | |
264 let excluded = new Set(); | 236 let excluded = new Set(); |
265 let currentDomain = domain ? domain.toUpperCase() : ""; | 237 let currentDomain = domain ? domain.toUpperCase() : ""; |
266 | 238 |
267 // This code is a performance hot-spot, which is why we've made certain | 239 // This code is a performance hot-spot, which is why we've made certain |
268 // micro-optimisations. Please be careful before making changes. | 240 // micro-optimisations. Please be careful before making changes. |
269 while (true) | 241 while (true) |
270 { | 242 { |
271 if (specificOnly && currentDomain == "") | 243 if (specificOnly && currentDomain == "") |
272 break; | 244 break; |
273 | 245 |
(...skipping 14 matching lines...) Expand all Loading... |
288 } | 260 } |
289 } | 261 } |
290 | 262 |
291 if (currentDomain == "") | 263 if (currentDomain == "") |
292 break; | 264 break; |
293 | 265 |
294 let nextDot = currentDomain.indexOf("."); | 266 let nextDot = currentDomain.indexOf("."); |
295 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 267 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
296 } | 268 } |
297 | 269 |
298 if (criteria < ElemHide.NO_UNCONDITIONAL) | 270 if (!specificOnly) |
299 selectors = getUnconditionalSelectors().concat(selectors); | 271 selectors = getUnconditionalSelectors().concat(selectors); |
300 | 272 |
301 return selectors; | 273 return selectors; |
302 } | 274 } |
303 }; | 275 }; |
OLD | NEW |