Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: background.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Patch Set: Stop using commonjs, fix other problems Created Feb. 21, 2017, 5:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « README.md ('k') | common.js » ('j') | ext/common.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 (function(global) 18 "use strict";
19
19 { 20 {
20 function EventEmitter() 21 function EventEmitter()
21 { 22 {
22 this._listeners = Object.create(null); 23 this._listeners = Object.create(null);
23 } 24 }
24 EventEmitter.prototype = { 25 EventEmitter.prototype = {
25 on: function(name, listener) 26 on(name, listener)
26 { 27 {
27 if (name in this._listeners) 28 if (name in this._listeners)
28 this._listeners[name].push(listener); 29 this._listeners[name].push(listener);
29 else 30 else
30 this._listeners[name] = [listener]; 31 this._listeners[name] = [listener];
31 }, 32 },
32 off: function(name, listener) 33 off(name, listener)
33 { 34 {
34 var listeners = this._listeners[name]; 35 let listeners = this._listeners[name];
35 if (listeners) 36 if (listeners)
36 { 37 {
37 var idx = listeners.indexOf(listener); 38 let idx = listeners.indexOf(listener);
38 if (idx != -1) 39 if (idx != -1)
39 listeners.splice(idx, 1); 40 listeners.splice(idx, 1);
40 } 41 }
41 }, 42 },
42 emit: function(name) 43 emit(name, ...args)
43 { 44 {
44 var listeners = this._listeners[name]; 45 let listeners = this._listeners[name];
45 if (listeners) 46 if (listeners)
46 { 47 {
47 for (var i = 0; i < listeners.length; i++) 48 for (let i = 0; i < listeners.length; i++)
48 listeners[i].apply(null, Array.prototype.slice.call(arguments, 1)); 49 listeners[i](...args);
49 } 50 }
50 } 51 }
51 }; 52 };
52 53
53 function updateFromURL(data) 54 function updateFromURL(data)
54 { 55 {
55 if (window.location.search) 56 if (window.location.search)
56 { 57 {
57 var params = window.location.search.substr(1).split("&"); 58 let params = window.location.search.substr(1).split("&");
58 for (var i = 0; i < params.length; i++) 59 for (let i = 0; i < params.length; i++)
59 { 60 {
60 var parts = params[i].split("=", 2); 61 let parts = params[i].split("=", 2);
61 if (parts.length == 2 && parts[0] in data) 62 if (parts.length == 2 && parts[0] in data)
62 data[parts[0]] = decodeURIComponent(parts[1]); 63 data[parts[0]] = decodeURIComponent(parts[1]);
63 } 64 }
64 } 65 }
65 } 66 }
66 67
67 var params = { 68 let params = {
68 blockedURLs: "", 69 blockedURLs: "",
69 filterlistsReinitialized: false, 70 filterlistsReinitialized: false,
70 addSubscription: false, 71 addSubscription: false,
71 filterError: false, 72 filterError: false,
72 downloadStatus: "synchronize_ok", 73 downloadStatus: "synchronize_ok",
73 showNotificationUI: false 74 showNotificationUI: false
74 }; 75 };
75 updateFromURL(params); 76 updateFromURL(params);
76 77
77 var modules = {}; 78 let modules = {};
78 global.require = function(module) 79 window.require = function(module)
79 { 80 {
80 return modules[module]; 81 return modules[module];
81 }; 82 };
82 83
83 modules.utils = { 84 modules.utils = {
84 Utils: { 85 Utils: {
85 getDocLink: function(link) 86 getDocLink(link)
86 { 87 {
87 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k); 88 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k);
88 }, 89 },
89 get appLocale() 90 get appLocale()
90 { 91 {
91 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 92 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
92 } 93 }
93 } 94 }
94 }; 95 };
95 96
96 modules.prefs = {Prefs: new EventEmitter()}; 97 modules.prefs = {Prefs: new EventEmitter()};
97 var prefs = { 98 let prefs = {
98 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [], 99 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [],
99 notifications_showui: params.showNotificationUI, 100 notifications_showui: params.showNotificationUI,
100 shouldShowBlockElementMenu: true, 101 shouldShowBlockElementMenu: true,
101 show_devtools_panel: true, 102 show_devtools_panel: true,
102 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc eptionrules.txt" 103 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc eptionrules.txt"
103 }; 104 };
104 Object.keys(prefs).forEach(function(key) 105 Object.keys(prefs).forEach(key =>
105 { 106 {
106 Object.defineProperty(modules.prefs.Prefs, key, { 107 Object.defineProperty(modules.prefs.Prefs, key, {
107 get: function() 108 get()
108 { 109 {
109 return prefs[key]; 110 return prefs[key];
110 }, 111 },
111 set: function(value) 112 set(value)
112 { 113 {
113 prefs[key] = value; 114 prefs[key] = value;
114 modules.prefs.Prefs.emit(key); 115 modules.prefs.Prefs.emit(key);
115 } 116 }
116 }); 117 });
117 }); 118 });
118 119
119 modules.notification = { 120 modules.notification = {
120 Notification: { 121 Notification: {
121 toggleIgnoreCategory: function(category) 122 toggleIgnoreCategory(category)
122 { 123 {
123 var categories = prefs.notifications_ignoredcategories; 124 let categories = prefs.notifications_ignoredcategories;
124 var index = categories.indexOf(category); 125 let index = categories.indexOf(category);
125 if (index == -1) 126 if (index == -1)
126 categories.push(category); 127 categories.push(category);
127 else 128 else
128 categories.splice(index, 1); 129 categories.splice(index, 1);
129 modules.prefs.Prefs.notifications_ignoredcategories = categories; 130 modules.prefs.Prefs.notifications_ignoredcategories = categories;
130 } 131 }
131 } 132 }
132 }; 133 };
133 134
135 /* eslint-disable object-shorthand */
Sebastian Noack 2017/02/21 12:21:20 Note that the object-shorthand rule has an ignoreC
kzar 2017/02/23 11:10:22 Done.
134 modules.subscriptionClasses = { 136 modules.subscriptionClasses = {
135 Subscription: function(url) 137 Subscription: function(url)
136 { 138 {
137 this.url = url; 139 this.url = url;
138 this._disabled = false; 140 this._disabled = false;
139 this._lastDownload = 1234; 141 this._lastDownload = 1234;
140 this.homepage = "https://easylist.adblockplus.org/"; 142 this.homepage = "https://easylist.adblockplus.org/";
141 this.downloadStatus = params.downloadStatus; 143 this.downloadStatus = params.downloadStatus;
142 }, 144 },
143 145
144 SpecialSubscription: function(url) 146 SpecialSubscription: function(url)
145 { 147 {
146 this.url = url; 148 this.url = url;
147 this.disabled = false; 149 this.disabled = false;
148 this.filters = knownFilters.slice(); 150 this.filters = knownFilters.slice();
149 } 151 }
150 }; 152 };
151 modules.subscriptionClasses.Subscription.fromURL = function(url) 153 modules.subscriptionClasses.Subscription.fromURL = function(url)
152 { 154 {
153 if (url in knownSubscriptions) 155 if (url in knownSubscriptions)
154 return knownSubscriptions[url]; 156 return knownSubscriptions[url];
155 157
156 if (/^https?:\/\//.test(url)) 158 if (/^https?:\/\//.test(url))
157 return new modules.subscriptionClasses.Subscription(url); 159 return new modules.subscriptionClasses.Subscription(url);
158 else 160 return new modules.subscriptionClasses.SpecialSubscription(url);
159 return new modules.subscriptionClasses.SpecialSubscription(url);
160 }; 161 };
161 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription; 162 /* eslint-enable object-shorthand */
163 modules.subscriptionClasses.DownloadableSubscription =
164 modules.subscriptionClasses.Subscription;
162 165
163 modules.subscriptionClasses.Subscription.prototype = 166 modules.subscriptionClasses.Subscription.prototype =
164 { 167 {
165 get disabled() 168 get disabled()
166 { 169 {
167 return this._disabled; 170 return this._disabled;
168 }, 171 },
169 set disabled(value) 172 set disabled(value)
170 { 173 {
171 this._disabled = value; 174 this._disabled = value;
172 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this); 175 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this);
173 }, 176 },
174 get lastDownload() 177 get lastDownload()
175 { 178 {
176 return this._lastDownload; 179 return this._lastDownload;
177 }, 180 },
178 set lastDownload(value) 181 set lastDownload(value)
179 { 182 {
180 this._lastDownload = value; 183 this._lastDownload = value;
181 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload", th is); 184 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload",
185 this);
182 } 186 }
183 }; 187 };
184 188
185 189
186 modules.filterStorage = { 190 modules.filterStorage = {
187 FilterStorage: { 191 FilterStorage: {
188 get subscriptions() 192 get subscriptions()
189 { 193 {
190 var subscriptions = []; 194 let subscriptions = [];
191 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) 195 for (let url in modules.filterStorage.FilterStorage.knownSubscriptions)
192 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]); 196 {
197 subscriptions.push(
198 modules.filterStorage.FilterStorage.knownSubscriptions[url]
199 );
200 }
193 return subscriptions; 201 return subscriptions;
194 }, 202 },
195 203
196 get knownSubscriptions() 204 get knownSubscriptions()
197 { 205 {
198 return knownSubscriptions; 206 return knownSubscriptions;
199 }, 207 },
200 208
201 addSubscription: function(subscription) 209 addSubscription(subscription)
202 { 210 {
203 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc riptions)) 211 let {fromURL} = modules.subscriptionClasses.Subscription;
212 let {FilterStorage} = modules.filterStorage;
213
214 if (!(subscription.url in FilterStorage.knownSubscriptions))
204 { 215 {
205 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub scription.fromURL(subscription.url); 216 knownSubscriptions[subscription.url] = fromURL(subscription.url);
206 modules.filterNotifier.FilterNotifier.emit("subscription.added", subsc ription); 217 modules.filterNotifier.FilterNotifier.emit("subscription.added",
218 subscription);
207 } 219 }
208 }, 220 },
209 221
210 removeSubscription: function(subscription) 222 removeSubscription(subscription)
211 { 223 {
212 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri ptions) 224 let {FilterStorage} = modules.filterStorage;
225
226 if (subscription.url in FilterStorage.knownSubscriptions)
213 { 227 {
214 delete knownSubscriptions[subscription.url]; 228 delete knownSubscriptions[subscription.url];
215 modules.filterNotifier.FilterNotifier.emit("subscription.removed", sub scription); 229 modules.filterNotifier.FilterNotifier.emit("subscription.removed",
230 subscription);
216 } 231 }
217 }, 232 },
218 233
219 addFilter: function(filter) 234 addFilter(filter)
220 { 235 {
221 for (var i = 0; i < customSubscription.filters.length; i++) 236 for (let i = 0; i < customSubscription.filters.length; i++)
222 { 237 {
223 if (customSubscription.filters[i].text == filter.text) 238 if (customSubscription.filters[i].text == filter.text)
224 return; 239 return;
225 } 240 }
226 customSubscription.filters.push(filter); 241 customSubscription.filters.push(filter);
227 modules.filterNotifier.FilterNotifier.emit("filter.added", filter); 242 modules.filterNotifier.FilterNotifier.emit("filter.added", filter);
228 }, 243 },
229 244
230 removeFilter: function(filter) 245 removeFilter(filter)
231 { 246 {
232 for (var i = 0; i < customSubscription.filters.length; i++) 247 for (let i = 0; i < customSubscription.filters.length; i++)
233 { 248 {
234 if (customSubscription.filters[i].text == filter.text) 249 if (customSubscription.filters[i].text == filter.text)
235 { 250 {
236 customSubscription.filters.splice(i, 1); 251 customSubscription.filters.splice(i, 1);
237 modules.filterNotifier.FilterNotifier.emit("filter.removed", filter) ; 252 modules.filterNotifier.FilterNotifier.emit("filter.removed",
253 filter);
238 return; 254 return;
239 } 255 }
240 } 256 }
241 } 257 }
242 } 258 }
243 }; 259 };
244 260
261 /* eslint-disable object-shorthand */
245 modules.filterClasses = { 262 modules.filterClasses = {
246 BlockingFilter: function() {}, 263 BlockingFilter: () => {},
247 Filter: function(text) 264 Filter: function(text)
248 { 265 {
249 this.text = text; 266 this.text = text;
250 this.disabled = false; 267 this.disabled = false;
251 }, 268 },
252 RegExpFilter: function() {} 269 RegExpFilter: () => {}
253 }; 270 };
271 /* eslint-enable object-shorthand */
254 modules.filterClasses.Filter.fromText = function(text) 272 modules.filterClasses.Filter.fromText = function(text)
255 { 273 {
256 return new modules.filterClasses.Filter(text); 274 return new modules.filterClasses.Filter(text);
257 }; 275 };
258 modules.filterClasses.RegExpFilter.typeMap = Object.create(null); 276 modules.filterClasses.RegExpFilter.typeMap = Object.create(null);
259 277
260 modules.filterValidation = 278 modules.filterValidation =
261 { 279 {
262 parseFilter: function(text) 280 parseFilter(text)
263 { 281 {
264 if (params.filterError) 282 if (params.filterError)
265 return {error: "Invalid filter"}; 283 return {error: "Invalid filter"};
266 return {filter: modules.filterClasses.Filter.fromText(text)}; 284 return {filter: modules.filterClasses.Filter.fromText(text)};
267 }, 285 },
268 parseFilters: function(text) 286 parseFilters(text)
269 { 287 {
270 if (params.filterError) 288 if (params.filterError)
271 return {errors: ["Invalid filter"]}; 289 return {errors: ["Invalid filter"]};
272 return { 290 return {
273 filters: text.split("\n") 291 filters: text.split("\n")
274 .filter(function(filter) {return !!filter;}) 292 .filter(filter => !!filter)
275 .map(modules.filterClasses.Filter.fromText), 293 .map(modules.filterClasses.Filter.fromText),
276 errors: [] 294 errors: []
277 }; 295 };
278 } 296 }
279 }; 297 };
280 298
281 modules.synchronizer = { 299 modules.synchronizer = {
282 Synchronizer: { 300 Synchronizer: {
283 _downloading: false, 301 _downloading: false,
284 execute: function(subscription, manual) 302 execute(subscription, manual)
285 { 303 {
286 modules.synchronizer.Synchronizer._downloading = true; 304 modules.synchronizer.Synchronizer._downloading = true;
287 modules.filterNotifier.FilterNotifier.emit( 305 modules.filterNotifier.FilterNotifier.emit(
288 "subscription.downloading", subscription 306 "subscription.downloading", subscription
289 ); 307 );
290 setTimeout(function() 308 setTimeout(() =>
291 { 309 {
292 modules.synchronizer.Synchronizer._downloading = false; 310 modules.synchronizer.Synchronizer._downloading = false;
293 subscription.lastDownload = Date.now() / 1000; 311 subscription.lastDownload = Date.now() / 1000;
294 }, 500); 312 }, 500);
295 }, 313 },
296 isExecuting: function(url) 314 isExecuting(url)
297 { 315 {
298 return modules.synchronizer.Synchronizer._downloading; 316 return modules.synchronizer.Synchronizer._downloading;
299 } 317 }
300 } 318 }
301 }; 319 };
302 320
303 modules.matcher = { 321 modules.matcher = {
304 defaultMatcher: { 322 defaultMatcher: {
305 matchesAny: function(url, requestType, docDomain, thirdParty) 323 matchesAny(url, requestType, docDomain, thirdParty)
306 { 324 {
307 var blocked = params.blockedURLs.split(","); 325 let blocked = params.blockedURLs.split(",");
308 if (blocked.indexOf(url) >= 0) 326 if (blocked.indexOf(url) >= 0)
309 return new modules.filterClasses.BlockingFilter(); 327 return new modules.filterClasses.BlockingFilter();
310 else 328 return null;
311 return null;
312 } 329 }
313 } 330 }
314 }; 331 };
315 332
316 modules.elemHideEmulation = { 333 modules.elemHideEmulation = {
317 ElemHideEmulation: {} 334 ElemHideEmulation: {}
318 }; 335 };
319 336
320 modules.filterNotifier = { 337 modules.filterNotifier = {
321 FilterNotifier: new EventEmitter() 338 FilterNotifier: new EventEmitter()
(...skipping 15 matching lines...) Expand all
337 354
338 modules.messaging = { 355 modules.messaging = {
339 port: new EventEmitter() 356 port: new EventEmitter()
340 }; 357 };
341 358
342 window.addEventListener("message", event => 359 window.addEventListener("message", event =>
343 { 360 {
344 if (event.data.type != "message") 361 if (event.data.type != "message")
345 return; 362 return;
346 let message = event.data.payload; 363 let message = event.data.payload;
347 let messageId = event.data.messageId; 364 let {messageId} = event.data;
348 let sender = { 365 let sender = {
349 page: new ext.Page(event.source) 366 page: new ext.Page(event.source)
350 }; 367 };
351 368
352 let listeners = modules.messaging.port._listeners[message.type]; 369 let listeners = modules.messaging.port._listeners[message.type];
353 if (!listeners) 370 if (!listeners)
354 return; 371 return;
355 372
356 function reply(message) 373 function reply(responseMessage)
357 { 374 {
358 event.source.postMessage({ 375 event.source.postMessage({
359 type: "response", 376 type: "response",
360 messageId: messageId, 377 messageId,
361 payload: message 378 payload: responseMessage
362 }, "*"); 379 }, "*");
363 } 380 }
364 381
365 for (let listener of listeners) 382 for (let listener of listeners)
366 { 383 {
367 let response = listener(message, sender); 384 let response = listener(message, sender);
368 if (response && typeof response.then == "function") 385 if (response && typeof response.then == "function")
369 { 386 {
370 response.then( 387 response.then(
371 reply, 388 reply,
372 reason => { 389 reason =>
390 {
373 console.error(reason); 391 console.error(reason);
374 reply(undefined); 392 reply(undefined);
375 } 393 }
376 ); 394 );
377 } 395 }
378 else if (typeof response != "undefined") 396 else if (typeof response != "undefined")
379 {
380 reply(response); 397 reply(response);
381 }
382 } 398 }
383 }); 399 });
384 400
385 global.Services = { 401 window.Services = {
386 vc: { 402 vc: {
387 compare: function(v1, v2) 403 compare(v1, v2)
388 { 404 {
389 return parseFloat(v1) - parseFloat(v2); 405 return parseFloat(v1) - parseFloat(v2);
390 } 406 }
391 } 407 }
392 }; 408 };
393 409
394 var filters = [ 410 let filters = [
395 "@@||alternate.de^$document", 411 "@@||alternate.de^$document",
396 "@@||der.postillion.com^$document", 412 "@@||der.postillion.com^$document",
397 "@@||taz.de^$document", 413 "@@||taz.de^$document",
398 "@@||amazon.de^$document", 414 "@@||amazon.de^$document",
399 "||biglemon.am/bg_poster/banner.jpg", 415 "||biglemon.am/bg_poster/banner.jpg",
400 "winfuture.de###header_logo_link", 416 "winfuture.de###header_logo_link",
401 "###WerbungObenRechts10_GesamtDIV", 417 "###WerbungObenRechts10_GesamtDIV",
402 "###WerbungObenRechts8_GesamtDIV", 418 "###WerbungObenRechts8_GesamtDIV",
403 "###WerbungObenRechts9_GesamtDIV", 419 "###WerbungObenRechts9_GesamtDIV",
404 "###WerbungUntenLinks4_GesamtDIV", 420 "###WerbungUntenLinks4_GesamtDIV",
405 "###WerbungUntenLinks7_GesamtDIV", 421 "###WerbungUntenLinks7_GesamtDIV",
406 "###WerbungUntenLinks8_GesamtDIV", 422 "###WerbungUntenLinks8_GesamtDIV",
407 "###WerbungUntenLinks9_GesamtDIV", 423 "###WerbungUntenLinks9_GesamtDIV",
408 "###Werbung_Sky", 424 "###Werbung_Sky",
409 "###Werbung_Wide", 425 "###Werbung_Wide",
410 "###__ligatus_placeholder__", 426 "###__ligatus_placeholder__",
411 "###ad-bereich1-08", 427 "###ad-bereich1-08",
412 "###ad-bereich1-superbanner", 428 "###ad-bereich1-superbanner",
413 "###ad-bereich2-08", 429 "###ad-bereich2-08",
414 "###ad-bereich2-skyscrapper" 430 "###ad-bereich2-skyscrapper"
415 ]; 431 ];
416 var knownFilters = filters.map(modules.filterClasses.Filter.fromText); 432 let knownFilters = filters.map(modules.filterClasses.Filter.fromText);
417 433
418 var subscriptions = [ 434 let subscriptions = [
419 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 435 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
420 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 436 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
421 "https://easylist-downloads.adblockplus.org/fanboy-social.txt", 437 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
422 "~user~786254" 438 "~user~786254"
423 ]; 439 ];
424 var knownSubscriptions = Object.create(null); 440 let knownSubscriptions = Object.create(null);
425 for (var subscriptionUrl of subscriptions) 441 for (let subscriptionUrl of subscriptions)
426 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl); 442 {
427 var customSubscription = knownSubscriptions["~user~786254"]; 443 knownSubscriptions[subscriptionUrl] =
444 modules.subscriptionClasses.Subscription.fromURL(subscriptionUrl);
445 }
446 let customSubscription = knownSubscriptions["~user~786254"];
428 447
429 if (params.addSubscription) 448 if (params.addSubscription)
430 { 449 {
431 // We don't know how long it will take for the page to fully load 450 // We don't know how long it will take for the page to fully load
432 // so we'll post the message after one second 451 // so we'll post the message after one second
433 setTimeout(function() 452 setTimeout(() =>
434 { 453 {
435 window.postMessage({ 454 window.postMessage({
436 type: "message", 455 type: "message",
437 payload: { 456 payload: {
438 title: "Custom subscription", 457 title: "Custom subscription",
439 url: "http://example.com/custom.txt", 458 url: "http://example.com/custom.txt",
440 confirm: true, 459 confirm: true,
441 type: "subscriptions.add" 460 type: "subscriptions.add"
442 } 461 }
443 }, "*"); 462 }, "*");
444 }, 1000); 463 }, 1000);
445 } 464 }
446 465
447 ext.devtools.onCreated.addListener(function(panel) 466 ext.devtools.onCreated.addListener(panel =>
448 { 467 {
449 // blocked request 468 // blocked request
450 panel.sendMessage({ 469 panel.sendMessage({
451 type: "add-record", 470 type: "add-record",
452 request: { 471 request: {
453 url: "http://adserver.example.com/ad_banner.png", 472 url: "http://adserver.example.com/ad_banner.png",
454 type: "IMAGE", 473 type: "IMAGE",
455 docDomain: "example.com" 474 docDomain: "example.com"
456 }, 475 },
457 filter: { 476 filter: {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 docDomain: "example.com" 532 docDomain: "example.com"
514 }, 533 },
515 filter: { 534 filter: {
516 text: "||example.com/some-annoying-popup$popup", 535 text: "||example.com/some-annoying-popup$popup",
517 whitelisted: false, 536 whitelisted: false,
518 userDefined: true, 537 userDefined: true,
519 subscription: null 538 subscription: null
520 } 539 }
521 }); 540 });
522 }); 541 });
523 })(this); 542 }
OLDNEW
« no previous file with comments | « README.md ('k') | common.js » ('j') | ext/common.js » ('J')

Powered by Google App Engine
This is Rietveld