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 18 matching lines...) Expand all Loading... | |
29 /** | 29 /** |
30 * Abstract base class for filter subscriptions | 30 * Abstract base class for filter subscriptions |
31 * | 31 * |
32 * @param {string} url download location of the subscription | 32 * @param {string} url download location of the subscription |
33 * @param {string} [title] title of the filter subscription | 33 * @param {string} [title] title of the filter subscription |
34 * @constructor | 34 * @constructor |
35 */ | 35 */ |
36 function Subscription(url, title) | 36 function Subscription(url, title) |
37 { | 37 { |
38 this.url = url; | 38 this.url = url; |
39 this.filters = []; | 39 |
40 this._filterText = []; | |
41 this._filters = []; | |
42 | |
40 if (title) | 43 if (title) |
41 this._title = title; | 44 this._title = title; |
45 | |
42 Subscription.knownSubscriptions.set(url, this); | 46 Subscription.knownSubscriptions.set(url, this); |
43 } | 47 } |
44 exports.Subscription = Subscription; | 48 exports.Subscription = Subscription; |
45 | 49 |
46 Subscription.prototype = | 50 Subscription.prototype = |
47 { | 51 { |
48 /** | 52 /** |
49 * Download location of the subscription | 53 * Download location of the subscription |
50 * @type {string} | 54 * @type {string} |
51 */ | 55 */ |
52 url: null, | 56 url: null, |
53 | 57 |
54 /** | 58 /** |
55 * Type of the subscription | 59 * Type of the subscription |
56 * @type {?string} | 60 * @type {?string} |
57 */ | 61 */ |
58 type: null, | 62 type: null, |
59 | 63 |
60 /** | 64 /** |
61 * Filters contained in the filter subscription | 65 * Filter text contained in the filter subscription. |
62 * @type {Array.<string>} | 66 * @type {Array.<string>} |
63 */ | 67 * @private |
64 filters: null, | 68 */ |
65 | 69 _filterText: null, |
hub
2018/11/19 17:47:49
shouldn't this be named `_filtersText` since it is
Manish Jethani
2018/11/20 00:19:39
I thought about calling it _filtersText but that s
hub
2018/11/20 19:30:19
my bad. let's leave it at that.
| |
66 /** | 70 |
67 * A list of {@link Filter} objects associated with the subscription in some | 71 /** |
68 * way. This is used by {@link INIParser} to temporarily cache objects | 72 * {@link Filter} objects corresponding to the subscription's filter text. |
69 * corresponding to the subscription's filter text. | 73 * @type {Array.<Filter>} |
70 * @type {?Array.<Filter>} | 74 * @private |
71 * @package | 75 */ |
72 */ | 76 _filters: null, |
73 filterObjects: null, | |
74 | 77 |
75 _title: null, | 78 _title: null, |
76 _fixedTitle: false, | 79 _fixedTitle: false, |
77 _disabled: false, | 80 _disabled: false, |
78 | 81 |
79 /** | 82 /** |
80 * Title of the filter subscription | 83 * Title of the filter subscription |
81 * @type {string} | 84 * @type {string} |
82 */ | 85 */ |
83 get title() | 86 get title() |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 }, | 127 }, |
125 set disabled(value) | 128 set disabled(value) |
126 { | 129 { |
127 if (value != this._disabled) | 130 if (value != this._disabled) |
128 { | 131 { |
129 let oldValue = this._disabled; | 132 let oldValue = this._disabled; |
130 this._disabled = value; | 133 this._disabled = value; |
131 filterNotifier.emit("subscription.disabled", this, value, oldValue); | 134 filterNotifier.emit("subscription.disabled", this, value, oldValue); |
132 } | 135 } |
133 return this._disabled; | 136 return this._disabled; |
137 }, | |
138 | |
139 /** | |
140 * The number of filters in the subscription. | |
141 * @type {number} | |
142 */ | |
143 get filterCount() | |
144 { | |
145 return this._filters.length; | |
146 }, | |
147 | |
148 /** | |
149 * Yields the text for each filter in the subscription. | |
150 * @yields {string} | |
151 */ | |
152 *filterText() | |
153 { | |
154 yield* this._filterText; | |
155 }, | |
156 | |
157 /** | |
158 * Yields the {@link Filter} object for each filter in the subscription. | |
159 * @yields {Filter} | |
160 */ | |
161 *filters() | |
162 { | |
163 yield* this._filters; | |
164 }, | |
165 | |
166 /** | |
167 * Returns the {@link Filter} object at the given 0-based index. | |
168 * @param {number} index | |
169 * @returns {?Filter} | |
170 */ | |
171 filterAt(index) | |
172 { | |
173 return this._filters[index] || null; | |
174 }, | |
175 | |
176 /** | |
177 * Returns the 0-based index of the given filter. | |
178 * @param {Filter} filter | |
179 * @param {number} [fromIndex] The index from which to start the search. | |
180 * @return {number} | |
181 */ | |
182 searchFilter(filter, fromIndex = 0) | |
183 { | |
184 return this._filterText.indexOf(filter.text, fromIndex); | |
185 }, | |
186 | |
187 /** | |
188 * Removes all filters from the subscription. | |
189 */ | |
190 clearFilters() | |
191 { | |
192 this._filterText = []; | |
193 this._filters = []; | |
194 }, | |
195 | |
196 /** | |
197 * Adds a filter to the subscription. | |
198 * @param {Filter} filter | |
199 */ | |
200 addFilter(filter) | |
201 { | |
202 this._filterText.push(filter.text); | |
203 this._filters.push(filter); | |
204 }, | |
205 | |
206 /** | |
207 * Inserts a filter into the subscription. | |
208 * @param {Filter} filter | |
209 * @param {number} index The index at which to insert the filter. | |
210 */ | |
211 insertFilterAt(filter, index) | |
212 { | |
213 this._filterText.splice(index, 0, filter.text); | |
214 this._filters.splice(index, 0, filter); | |
215 }, | |
216 | |
217 /** | |
218 * Deletes a filter from the subscription. | |
219 * @param {number} index The index at which to delete the filter. | |
220 */ | |
221 deleteFilterAt(index) | |
222 { | |
223 // Ignore index if out of bounds on the negative side, for consistency. | |
224 if (index < 0) | |
225 return; | |
226 | |
227 this._filterText.splice(index, 1); | |
228 this._filters.splice(index, 1); | |
134 }, | 229 }, |
135 | 230 |
136 /** | 231 /** |
137 * Serializes the subscription for writing out on disk. | 232 * Serializes the subscription for writing out on disk. |
138 * @yields {string} | 233 * @yields {string} |
139 */ | 234 */ |
140 *serialize() | 235 *serialize() |
141 { | 236 { |
142 let {url, type, _title, _fixedTitle, _disabled} = this; | 237 let {url, type, _title, _fixedTitle, _disabled} = this; |
143 | 238 |
144 yield "[Subscription]"; | 239 yield "[Subscription]"; |
145 yield "url=" + url; | 240 yield "url=" + url; |
146 | 241 |
147 if (type) | 242 if (type) |
148 yield "type=" + type; | 243 yield "type=" + type; |
149 if (_title) | 244 if (_title) |
150 yield "title=" + _title; | 245 yield "title=" + _title; |
151 if (_fixedTitle) | 246 if (_fixedTitle) |
152 yield "fixedTitle=true"; | 247 yield "fixedTitle=true"; |
153 if (_disabled) | 248 if (_disabled) |
154 yield "disabled=true"; | 249 yield "disabled=true"; |
155 }, | 250 }, |
156 | 251 |
157 *serializeFilters() | 252 *serializeFilters() |
158 { | 253 { |
159 let {filters} = this; | 254 let {_filterText} = this; |
160 | 255 |
161 yield "[Subscription filters]"; | 256 yield "[Subscription filters]"; |
162 | 257 |
163 for (let text of filters) | 258 for (let text of _filterText) |
164 yield text.replace(/\[/g, "\\["); | 259 yield text.replace(/\[/g, "\\["); |
165 }, | 260 }, |
166 | 261 |
167 toString() | 262 toString() |
168 { | 263 { |
169 return [...this.serialize()].join("\n"); | 264 return [...this.serialize()].join("\n"); |
170 } | 265 } |
171 }; | 266 }; |
172 | 267 |
173 /** | 268 /** |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 | 430 |
336 /** | 431 /** |
337 * Creates a new user-defined filter group and adds the given filter to it. | 432 * Creates a new user-defined filter group and adds the given filter to it. |
338 * This group will act as the default group for this filter type. | 433 * This group will act as the default group for this filter type. |
339 * @param {Filter} filter | 434 * @param {Filter} filter |
340 * @return {SpecialSubscription} | 435 * @return {SpecialSubscription} |
341 */ | 436 */ |
342 SpecialSubscription.createForFilter = function(filter) | 437 SpecialSubscription.createForFilter = function(filter) |
343 { | 438 { |
344 let subscription = SpecialSubscription.create(); | 439 let subscription = SpecialSubscription.create(); |
345 subscription.filters.push(filter.text); | 440 subscription.addFilter(filter); |
346 for (let [type, class_] of SpecialSubscription.defaultsMap) | 441 for (let [type, class_] of SpecialSubscription.defaultsMap) |
347 { | 442 { |
348 if (filter instanceof class_) | 443 if (filter instanceof class_) |
349 subscription.defaults = [type]; | 444 subscription.defaults = [type]; |
350 } | 445 } |
351 if (!subscription.defaults) | 446 if (!subscription.defaults) |
352 subscription.defaults = ["blocking"]; | 447 subscription.defaults = ["blocking"]; |
353 return subscription; | 448 return subscription; |
354 }; | 449 }; |
355 | 450 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 if (errors) | 686 if (errors) |
592 yield "errors=" + errors; | 687 yield "errors=" + errors; |
593 if (version) | 688 if (version) |
594 yield "version=" + version; | 689 yield "version=" + version; |
595 if (requiredVersion) | 690 if (requiredVersion) |
596 yield "requiredVersion=" + requiredVersion; | 691 yield "requiredVersion=" + requiredVersion; |
597 if (downloadCount) | 692 if (downloadCount) |
598 yield "downloadCount=" + downloadCount; | 693 yield "downloadCount=" + downloadCount; |
599 } | 694 } |
600 }); | 695 }); |
LEFT | RIGHT |