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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 /** | 100 /** |
101 * Filter type as a string, e.g. "blocking". | 101 * Filter type as a string, e.g. "blocking". |
102 * @type {string} | 102 * @type {string} |
103 */ | 103 */ |
104 get type() | 104 get type() |
105 { | 105 { |
106 throw new Error("Please define filter type in the subclass"); | 106 throw new Error("Please define filter type in the subclass"); |
107 }, | 107 }, |
108 | 108 |
109 /** | 109 /** |
110 * Yields subscriptions to which the filter belongs. | |
111 * @yields {Subscription} | |
112 */ | |
113 *subscriptions() | |
114 { | |
115 if (this._subscriptions) | |
116 { | |
117 if (this._subscriptions instanceof Set) | |
118 yield* this._subscriptions; | |
119 else | |
120 yield this._subscriptions; | |
121 } | |
122 }, | |
123 | |
124 /** | |
125 * The number of subscriptions to which the filter belongs. | |
126 * @type {number} | |
127 */ | |
128 get subscriptionCount() | |
129 { | |
130 if (this._subscriptions instanceof Set) | |
131 return this._subscriptions.size; | |
132 | |
133 return this._subscriptions ? 1 : 0; | |
134 }, | |
135 | |
136 /** | |
137 * Adds a subscription to the set of subscriptions to which the filter | |
138 * belongs. | |
139 * @param {Subscription} subscription | |
140 */ | |
141 addSubscription(subscription) | |
142 { | |
143 // Since we use truthy checks in our logic, we must avoid adding a | |
144 // subscription that isn't a non-null object. | |
145 if (subscription === null || typeof subscription != "object") | |
146 return; | |
147 | |
148 if (this._subscriptions) | |
149 { | |
150 if (this._subscriptions instanceof Set) | |
151 this._subscriptions.add(subscription); | |
152 else if (subscription != this._subscriptions) | |
153 this._subscriptions = new Set([this._subscriptions, subscription]); | |
154 } | |
155 else | |
156 { | |
157 this._subscriptions = subscription; | |
158 } | |
159 }, | |
160 | |
161 /** | |
162 * Removes a subscription from the set of subscriptions to which the filter | |
163 * belongs. | |
164 * @param {Subscription} subscription | |
165 */ | |
166 removeSubscription(subscription) | |
167 { | |
168 if (this._subscriptions) | |
169 { | |
170 if (this._subscriptions instanceof Set) | |
171 { | |
172 this._subscriptions.delete(subscription); | |
173 | |
174 if (this._subscriptions.size == 1) | |
175 this._subscriptions = [...this._subscriptions][0]; | |
176 } | |
177 else if (subscription == this._subscriptions) | |
178 { | |
179 this._subscriptions = null; | |
180 } | |
181 } | |
182 }, | |
183 | |
184 /** | |
185 * Serializes the filter for writing out on disk. | 110 * Serializes the filter for writing out on disk. |
186 * @yields {string} | 111 * @yields {string} |
187 */ | 112 */ |
188 *serialize() | 113 *serialize() |
189 { | 114 { |
190 let {text} = this; | 115 let {text} = this; |
191 | 116 |
192 yield "[Filter]"; | 117 yield "[Filter]"; |
193 yield "text=" + text; | 118 yield "text=" + text; |
194 }, | 119 }, |
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 | 1362 |
1438 /** | 1363 /** |
1439 * Script that should be executed | 1364 * Script that should be executed |
1440 * @type {string} | 1365 * @type {string} |
1441 */ | 1366 */ |
1442 get script() | 1367 get script() |
1443 { | 1368 { |
1444 return this.body; | 1369 return this.body; |
1445 } | 1370 } |
1446 }); | 1371 }); |
OLD | NEW |