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

Powered by Google App Engine
This is Rietveld