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

Powered by Google App Engine
This is Rietveld