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 11 matching lines...) Expand all Loading... |
22 * instances and ElemHide. | 22 * instances and ElemHide. |
23 */ | 23 */ |
24 | 24 |
25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
27 | 27 |
28 const {FilterStorage} = require("./filterStorage"); | 28 const {FilterStorage} = require("./filterStorage"); |
29 const {FilterNotifier} = require("./filterNotifier"); | 29 const {FilterNotifier} = require("./filterNotifier"); |
30 const {ElemHide} = require("./elemHide"); | 30 const {ElemHide} = require("./elemHide"); |
31 const {ElemHideEmulation} = require("./elemHideEmulation"); | 31 const {ElemHideEmulation} = require("./elemHideEmulation"); |
| 32 const {Snippets} = require("./snippets"); |
32 const {defaultMatcher} = require("./matcher"); | 33 const {defaultMatcher} = require("./matcher"); |
33 const {ActiveFilter, RegExpFilter, | 34 const {ActiveFilter, RegExpFilter, |
34 ElemHideBase, ElemHideEmulationFilter} = require("./filterClasses"); | 35 ElemHideBase, ElemHideEmulationFilter, |
| 36 SnippetFilter} = require("./filterClasses"); |
35 const {Prefs} = require("prefs"); | 37 const {Prefs} = require("prefs"); |
36 | 38 |
37 /** | 39 /** |
38 * Increases on filter changes, filters will be saved if it exceeds 1. | 40 * Increases on filter changes, filters will be saved if it exceeds 1. |
39 * @type {number} | 41 * @type {number} |
40 */ | 42 */ |
41 let isDirty = 0; | 43 let isDirty = 0; |
42 | 44 |
43 /** | 45 /** |
44 * This object can be used to change properties of the filter change listeners. | 46 * This object can be used to change properties of the filter change listeners. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 150 |
149 if (filter instanceof RegExpFilter) | 151 if (filter instanceof RegExpFilter) |
150 defaultMatcher.add(filter); | 152 defaultMatcher.add(filter); |
151 else if (filter instanceof ElemHideBase) | 153 else if (filter instanceof ElemHideBase) |
152 { | 154 { |
153 if (filter instanceof ElemHideEmulationFilter) | 155 if (filter instanceof ElemHideEmulationFilter) |
154 ElemHideEmulation.add(filter); | 156 ElemHideEmulation.add(filter); |
155 else | 157 else |
156 ElemHide.add(filter); | 158 ElemHide.add(filter); |
157 } | 159 } |
| 160 else if (filter instanceof SnippetFilter) |
| 161 Snippets.add(filter); |
158 } | 162 } |
159 | 163 |
160 /** | 164 /** |
161 * Notifies Matcher instances or ElemHide object about removal of a filter | 165 * Notifies Matcher instances or ElemHide object about removal of a filter |
162 * if necessary. | 166 * if necessary. |
163 * @param {Filter} filter filter that has been removed | 167 * @param {Filter} filter filter that has been removed |
164 */ | 168 */ |
165 function removeFilter(filter) | 169 function removeFilter(filter) |
166 { | 170 { |
167 if (!(filter instanceof ActiveFilter)) | 171 if (!(filter instanceof ActiveFilter)) |
(...skipping 13 matching lines...) Expand all Loading... |
181 | 185 |
182 if (filter instanceof RegExpFilter) | 186 if (filter instanceof RegExpFilter) |
183 defaultMatcher.remove(filter); | 187 defaultMatcher.remove(filter); |
184 else if (filter instanceof ElemHideBase) | 188 else if (filter instanceof ElemHideBase) |
185 { | 189 { |
186 if (filter instanceof ElemHideEmulationFilter) | 190 if (filter instanceof ElemHideEmulationFilter) |
187 ElemHideEmulation.remove(filter); | 191 ElemHideEmulation.remove(filter); |
188 else | 192 else |
189 ElemHide.remove(filter); | 193 ElemHide.remove(filter); |
190 } | 194 } |
| 195 else if (filter instanceof SnippetFilter) |
| 196 Snippets.remove(filter); |
191 } | 197 } |
192 | 198 |
193 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; | 199 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; |
194 | 200 |
195 function addFilters(filters) | 201 function addFilters(filters) |
196 { | 202 { |
197 // We add filters using pseudo-random ordering. Reason is that ElemHide will | 203 // We add filters using pseudo-random ordering. Reason is that ElemHide will |
198 // assign consecutive filter IDs that might be visible to the website. The | 204 // assign consecutive filter IDs that might be visible to the website. The |
199 // randomization makes sure that no conclusion can be made about the actual | 205 // randomization makes sure that no conclusion can be made about the actual |
200 // filters applying there. We have ten prime numbers to use as iteration step, | 206 // filters applying there. We have ten prime numbers to use as iteration step, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 FilterListener.setDirty(1); | 306 FilterListener.setDirty(1); |
301 } | 307 } |
302 | 308 |
303 function onLoad() | 309 function onLoad() |
304 { | 310 { |
305 isDirty = 0; | 311 isDirty = 0; |
306 | 312 |
307 defaultMatcher.clear(); | 313 defaultMatcher.clear(); |
308 ElemHide.clear(); | 314 ElemHide.clear(); |
309 ElemHideEmulation.clear(); | 315 ElemHideEmulation.clear(); |
| 316 Snippets.clear(); |
310 for (let subscription of FilterStorage.subscriptions) | 317 for (let subscription of FilterStorage.subscriptions) |
311 { | 318 { |
312 if (!subscription.disabled) | 319 if (!subscription.disabled) |
313 addFilters(subscription.filters); | 320 addFilters(subscription.filters); |
314 } | 321 } |
315 } | 322 } |
316 | 323 |
317 function onSave() | 324 function onSave() |
318 { | 325 { |
319 isDirty = 0; | 326 isDirty = 0; |
320 } | 327 } |
OLD | NEW |