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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 /** | 20 /** |
21 * @fileOverview Element hiding implementation. | 21 * @fileOverview Element hiding implementation. |
22 */ | 22 */ |
23 | 23 |
24 const {ElemHideExceptions} = require("./elemHideExceptions"); | 24 const {ElemHideExceptions} = require("./elemHideExceptions"); |
25 const {filterNotifier} = require("./filterNotifier"); | 25 const {filterNotifier} = require("./filterNotifier"); |
| 26 const {suffixes} = require("./domain"); |
26 | 27 |
27 /** | 28 /** |
28 * The maximum number of selectors in a CSS rule. This is used by | 29 * The maximum number of selectors in a CSS rule. This is used by |
29 * <code>{@link createStyleSheet}</code> to split up a long list of selectors | 30 * <code>{@link createStyleSheet}</code> to split up a long list of selectors |
30 * into multiple rules. | 31 * into multiple rules. |
31 * @const {number} | 32 * @const {number} |
32 * @default | 33 * @default |
33 */ | 34 */ |
34 const selectorGroupSize = 1024; | 35 const selectorGroupSize = 1024; |
35 | 36 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 * @param {boolean} specificOnly Whether selectors from generic filters should | 163 * @param {boolean} specificOnly Whether selectors from generic filters should |
163 * be included. | 164 * be included. |
164 * | 165 * |
165 * @returns {Array.<string>} The list of selectors. | 166 * @returns {Array.<string>} The list of selectors. |
166 */ | 167 */ |
167 function getConditionalSelectors(domain, specificOnly) | 168 function getConditionalSelectors(domain, specificOnly) |
168 { | 169 { |
169 let selectors = []; | 170 let selectors = []; |
170 | 171 |
171 let excluded = new Set(); | 172 let excluded = new Set(); |
172 let currentDomain = domain; | |
173 | 173 |
174 // This code is a performance hot-spot, which is why we've made certain | 174 for (let currentDomain of suffixes(domain, !specificOnly)) |
175 // micro-optimisations. Please be careful before making changes. | |
176 while (true) | |
177 { | 175 { |
178 if (specificOnly && currentDomain == "") | |
179 break; | |
180 | |
181 let filters = filtersByDomain.get(currentDomain); | 176 let filters = filtersByDomain.get(currentDomain); |
182 if (filters) | 177 if (filters) |
183 { | 178 { |
184 for (let [filter, isIncluded] of filters) | 179 for (let [filter, isIncluded] of filters) |
185 { | 180 { |
186 if (!isIncluded) | 181 if (!isIncluded) |
187 { | 182 { |
188 excluded.add(filter); | 183 excluded.add(filter); |
189 } | 184 } |
190 else | 185 else |
191 { | 186 { |
192 let {selector} = filter; | 187 let {selector} = filter; |
193 if ((excluded.size == 0 || !excluded.has(filter)) && | 188 if ((excluded.size == 0 || !excluded.has(filter)) && |
194 !ElemHideExceptions.getException(selector, domain)) | 189 !ElemHideExceptions.getException(selector, domain)) |
195 { | 190 { |
196 selectors.push(selector); | 191 selectors.push(selector); |
197 } | 192 } |
198 } | 193 } |
199 } | 194 } |
200 } | 195 } |
201 | |
202 if (currentDomain == "") | |
203 break; | |
204 | |
205 let nextDot = currentDomain.indexOf("."); | |
206 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | |
207 } | 196 } |
208 | 197 |
209 return selectors; | 198 return selectors; |
210 } | 199 } |
211 | 200 |
212 /** | 201 /** |
213 * Returns the default style sheet that applies on all domains. | 202 * Returns the default style sheet that applies on all domains. |
214 * @returns {string} | 203 * @returns {string} |
215 */ | 204 */ |
216 function getDefaultStyleSheet() | 205 function getDefaultStyleSheet() |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 { | 506 { |
518 let styleSheet = ""; | 507 let styleSheet = ""; |
519 | 508 |
520 for (let selectorGroup of splitSelectors(selectors)) | 509 for (let selectorGroup of splitSelectors(selectors)) |
521 styleSheet += createRule(selectorGroup); | 510 styleSheet += createRule(selectorGroup); |
522 | 511 |
523 return styleSheet; | 512 return styleSheet; |
524 } | 513 } |
525 | 514 |
526 exports.createStyleSheet = createStyleSheet; | 515 exports.createStyleSheet = createStyleSheet; |
OLD | NEW |