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 20 matching lines...) Expand all Loading... |
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 | 39 |
40 this._filterText = []; | 40 this._filterText = []; |
41 this._filters = []; | |
42 | 41 |
43 if (title) | 42 if (title) |
44 this._title = title; | 43 this._title = title; |
45 | 44 |
46 Subscription.knownSubscriptions.set(url, this); | 45 Subscription.knownSubscriptions.set(url, this); |
47 } | 46 } |
48 exports.Subscription = Subscription; | 47 exports.Subscription = Subscription; |
49 | 48 |
50 Subscription.prototype = | 49 Subscription.prototype = |
51 { | 50 { |
52 /** | 51 /** |
53 * Download location of the subscription | 52 * Download location of the subscription |
54 * @type {string} | 53 * @type {string} |
55 */ | 54 */ |
56 url: null, | 55 url: null, |
57 | 56 |
58 /** | 57 /** |
59 * Type of the subscription | 58 * Type of the subscription |
60 * @type {?string} | 59 * @type {?string} |
61 */ | 60 */ |
62 type: null, | 61 type: null, |
63 | 62 |
64 /** | 63 /** |
65 * Filter text contained in the filter subscription. | 64 * Filter text contained in the filter subscription. |
66 * @type {Array.<string>} | 65 * @type {Array.<string>} |
67 * @private | 66 * @private |
68 */ | 67 */ |
69 _filterText: null, | 68 _filterText: null, |
70 | 69 |
71 /** | |
72 * {@link Filter} objects corresponding to the subscription's filter text. | |
73 * @type {Array.<Filter>} | |
74 * @private | |
75 */ | |
76 _filters: null, | |
77 | |
78 _title: null, | 70 _title: null, |
79 _fixedTitle: false, | 71 _fixedTitle: false, |
80 _disabled: false, | 72 _disabled: false, |
81 | 73 |
82 /** | 74 /** |
83 * Title of the filter subscription | 75 * Title of the filter subscription |
84 * @type {string} | 76 * @type {string} |
85 */ | 77 */ |
86 get title() | 78 get title() |
87 { | 79 { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 127 } |
136 return this._disabled; | 128 return this._disabled; |
137 }, | 129 }, |
138 | 130 |
139 /** | 131 /** |
140 * The number of filters in the subscription. | 132 * The number of filters in the subscription. |
141 * @type {number} | 133 * @type {number} |
142 */ | 134 */ |
143 get filterCount() | 135 get filterCount() |
144 { | 136 { |
145 return this._filters.length; | 137 return this._filterText.length; |
146 }, | 138 }, |
147 | 139 |
148 /** | 140 /** |
149 * Yields the text for each filter in the subscription. | 141 * Yields the text for each filter in the subscription. |
150 * @yields {string} | 142 * @yields {string} |
151 */ | 143 */ |
152 *filterText() | 144 *filterText() |
153 { | 145 { |
154 yield* this._filterText; | 146 yield* this._filterText; |
155 }, | 147 }, |
156 | 148 |
157 /** | 149 /** |
158 * Yields the {@link Filter} object for each filter in the subscription. | 150 * Returns the filter text at the given 0-based index. |
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 | 151 * @param {number} index |
169 * @returns {?Filter} | 152 * @returns {?Filter} |
170 */ | 153 */ |
171 filterAt(index) | 154 filterTextAt(index) |
172 { | 155 { |
173 return this._filters[index] || null; | 156 return this._filterText[index] || null; |
174 }, | 157 }, |
175 | 158 |
176 /** | 159 /** |
177 * Returns the 0-based index of the given filter. | 160 * Returns the 0-based index of the given filter. |
178 * @param {Filter} filter | 161 * @param {Filter} filter |
179 * @param {number} [fromIndex] The index from which to start the search. | 162 * @param {number} [fromIndex] The index from which to start the search. |
180 * @return {number} | 163 * @return {number} |
181 */ | 164 */ |
182 searchFilter(filter, fromIndex = 0) | 165 searchFilter(filter, fromIndex = 0) |
183 { | 166 { |
184 return this._filterText.indexOf(filter.text, fromIndex); | 167 return this._filterText.indexOf(filter.text, fromIndex); |
185 }, | 168 }, |
186 | 169 |
187 /** | 170 /** |
188 * Removes all filters from the subscription. | 171 * Removes all filters from the subscription. |
189 */ | 172 */ |
190 clearFilters() | 173 clearFilters() |
191 { | 174 { |
192 this._filterText = []; | 175 this._filterText = []; |
193 this._filters = []; | |
194 }, | 176 }, |
195 | 177 |
196 /** | 178 /** |
197 * Adds a filter to the subscription. | 179 * Adds a filter to the subscription. |
198 * @param {Filter} filter | 180 * @param {Filter} filter |
199 */ | 181 */ |
200 addFilter(filter) | 182 addFilter(filter) |
201 { | 183 { |
202 this._filterText.push(filter.text); | 184 this._filterText.push(filter.text); |
203 this._filters.push(filter); | 185 }, |
| 186 |
| 187 /** |
| 188 * Adds a filter to the subscription. |
| 189 * @param {string} filterText |
| 190 */ |
| 191 addFilterText(filterText) |
| 192 { |
| 193 this._filterText.push(filterText); |
204 }, | 194 }, |
205 | 195 |
206 /** | 196 /** |
207 * Inserts a filter into the subscription. | 197 * Inserts a filter into the subscription. |
208 * @param {Filter} filter | 198 * @param {Filter} filter |
209 * @param {number} index The index at which to insert the filter. | 199 * @param {number} index The index at which to insert the filter. |
210 */ | 200 */ |
211 insertFilterAt(filter, index) | 201 insertFilterAt(filter, index) |
212 { | 202 { |
213 this._filterText.splice(index, 0, filter.text); | 203 this._filterText.splice(index, 0, filter.text); |
214 this._filters.splice(index, 0, filter); | |
215 }, | 204 }, |
216 | 205 |
217 /** | 206 /** |
218 * Deletes a filter from the subscription. | 207 * Deletes a filter from the subscription. |
219 * @param {number} index The index at which to delete the filter. | 208 * @param {number} index The index at which to delete the filter. |
220 */ | 209 */ |
221 deleteFilterAt(index) | 210 deleteFilterAt(index) |
222 { | 211 { |
223 // Ignore index if out of bounds on the negative side, for consistency. | 212 // Ignore index if out of bounds on the negative side, for consistency. |
224 if (index < 0) | 213 if (index < 0) |
225 return; | 214 return; |
226 | 215 |
227 this._filterText.splice(index, 1); | 216 this._filterText.splice(index, 1); |
228 this._filters.splice(index, 1); | |
229 }, | 217 }, |
230 | 218 |
231 /** | 219 /** |
232 * Serializes the subscription for writing out on disk. | 220 * Serializes the subscription for writing out on disk. |
233 * @yields {string} | 221 * @yields {string} |
234 */ | 222 */ |
235 *serialize() | 223 *serialize() |
236 { | 224 { |
237 let {url, type, _title, _fixedTitle, _disabled} = this; | 225 let {url, type, _title, _fixedTitle, _disabled} = this; |
238 | 226 |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 if (errors) | 674 if (errors) |
687 yield "errors=" + errors; | 675 yield "errors=" + errors; |
688 if (version) | 676 if (version) |
689 yield "version=" + version; | 677 yield "version=" + version; |
690 if (requiredVersion) | 678 if (requiredVersion) |
691 yield "requiredVersion=" + requiredVersion; | 679 yield "requiredVersion=" + requiredVersion; |
692 if (downloadCount) | 680 if (downloadCount) |
693 yield "downloadCount=" + downloadCount; | 681 yield "downloadCount=" + downloadCount; |
694 } | 682 } |
695 }); | 683 }); |
OLD | NEW |