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: Started addressing Sebastian's initial feedback Created Feb. 23, 2017, 11:09 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
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
134 modules.subscriptionClasses = { 135 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 { 136 {
153 if (url in knownSubscriptions) 137 this.url = url;
154 return knownSubscriptions[url]; 138 this._disabled = false;
155 139 this._lastDownload = 1234;
156 if (/^https?:\/\//.test(url)) 140 this.homepage = "https://easylist.adblockplus.org/";
157 return new modules.subscriptionClasses.Subscription(url); 141 this.downloadStatus = params.downloadStatus;
158 else 142 }
159 return new modules.subscriptionClasses.SpecialSubscription(url); 143 Subscription.prototype =
160 };
161 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription;
162
163 modules.subscriptionClasses.Subscription.prototype =
164 { 144 {
165 get disabled() 145 get disabled()
166 { 146 {
167 return this._disabled; 147 return this._disabled;
168 }, 148 },
169 set disabled(value) 149 set disabled(value)
170 { 150 {
171 this._disabled = value; 151 this._disabled = value;
172 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this); 152 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this);
173 }, 153 },
174 get lastDownload() 154 get lastDownload()
175 { 155 {
176 return this._lastDownload; 156 return this._lastDownload;
177 }, 157 },
178 set lastDownload(value) 158 set lastDownload(value)
179 { 159 {
180 this._lastDownload = value; 160 this._lastDownload = value;
181 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload", th is); 161 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload",
162 this);
182 } 163 }
183 }; 164 };
165 Subscription.fromURL = function(url)
166 {
167 if (url in knownSubscriptions)
168 return knownSubscriptions[url];
184 169
170 if (/^https?:\/\//.test(url))
171 return new modules.subscriptionClasses.Subscription(url);
172 return new modules.subscriptionClasses.SpecialSubscription(url);
173 };
174
175 function SpecialSubscription(url)
176 {
177 this.url = url;
178 this.disabled = false;
179 this.filters = knownFilters.slice();
180 }
181
182 modules.subscriptionClasses = {
183 Subscription,
184 SpecialSubscription,
185 DownloadableSubscription: Subscription
186 };
185 187
186 modules.filterStorage = { 188 modules.filterStorage = {
187 FilterStorage: { 189 FilterStorage: {
188 get subscriptions() 190 get subscriptions()
189 { 191 {
190 var subscriptions = []; 192 let subscriptions = [];
191 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) 193 for (let url in modules.filterStorage.FilterStorage.knownSubscriptions)
192 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]); 194 {
195 subscriptions.push(
196 modules.filterStorage.FilterStorage.knownSubscriptions[url]
197 );
198 }
193 return subscriptions; 199 return subscriptions;
194 }, 200 },
195 201
196 get knownSubscriptions() 202 get knownSubscriptions()
197 { 203 {
198 return knownSubscriptions; 204 return knownSubscriptions;
199 }, 205 },
200 206
201 addSubscription: function(subscription) 207 addSubscription(subscription)
202 { 208 {
203 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc riptions)) 209 let {fromURL} = modules.subscriptionClasses.Subscription;
210 let {FilterStorage} = modules.filterStorage;
211
212 if (!(subscription.url in FilterStorage.knownSubscriptions))
204 { 213 {
205 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub scription.fromURL(subscription.url); 214 knownSubscriptions[subscription.url] = fromURL(subscription.url);
206 modules.filterNotifier.FilterNotifier.emit("subscription.added", subsc ription); 215 modules.filterNotifier.FilterNotifier.emit("subscription.added",
216 subscription);
207 } 217 }
208 }, 218 },
209 219
210 removeSubscription: function(subscription) 220 removeSubscription(subscription)
211 { 221 {
212 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri ptions) 222 let {FilterStorage} = modules.filterStorage;
223
224 if (subscription.url in FilterStorage.knownSubscriptions)
213 { 225 {
214 delete knownSubscriptions[subscription.url]; 226 delete knownSubscriptions[subscription.url];
215 modules.filterNotifier.FilterNotifier.emit("subscription.removed", sub scription); 227 modules.filterNotifier.FilterNotifier.emit("subscription.removed",
228 subscription);
216 } 229 }
217 }, 230 },
218 231
219 addFilter: function(filter) 232 addFilter(filter)
220 { 233 {
221 for (var i = 0; i < customSubscription.filters.length; i++) 234 for (let i = 0; i < customSubscription.filters.length; i++)
222 { 235 {
223 if (customSubscription.filters[i].text == filter.text) 236 if (customSubscription.filters[i].text == filter.text)
224 return; 237 return;
225 } 238 }
226 customSubscription.filters.push(filter); 239 customSubscription.filters.push(filter);
227 modules.filterNotifier.FilterNotifier.emit("filter.added", filter); 240 modules.filterNotifier.FilterNotifier.emit("filter.added", filter);
228 }, 241 },
229 242
230 removeFilter: function(filter) 243 removeFilter(filter)
231 { 244 {
232 for (var i = 0; i < customSubscription.filters.length; i++) 245 for (let i = 0; i < customSubscription.filters.length; i++)
233 { 246 {
234 if (customSubscription.filters[i].text == filter.text) 247 if (customSubscription.filters[i].text == filter.text)
235 { 248 {
236 customSubscription.filters.splice(i, 1); 249 customSubscription.filters.splice(i, 1);
237 modules.filterNotifier.FilterNotifier.emit("filter.removed", filter) ; 250 modules.filterNotifier.FilterNotifier.emit("filter.removed",
251 filter);
238 return; 252 return;
239 } 253 }
240 } 254 }
241 } 255 }
242 } 256 }
243 }; 257 };
244 258
245 modules.filterClasses = { 259 function Filter(text)
246 BlockingFilter: function() {}, 260 {
247 Filter: function(text) 261 this.text = text;
248 { 262 this.disabled = false;
249 this.text = text; 263 }
250 this.disabled = false; 264 Filter.fromText = text =>
251 },
252 RegExpFilter: function() {}
253 };
254 modules.filterClasses.Filter.fromText = function(text)
255 { 265 {
256 return new modules.filterClasses.Filter(text); 266 return new modules.filterClasses.Filter(text);
257 }; 267 };
258 modules.filterClasses.RegExpFilter.typeMap = Object.create(null);
259 268
260 modules.filterValidation = 269 function BlockingFilter()
261 { 270 {
262 parseFilter: function(text) 271 }
272
273 function RegExpFilter()
274 {
275 }
276 RegExpFilter.typeMap = Object.create(null);
277
278 modules.filterClasses = {
279 BlockingFilter,
280 Filter,
281 RegExpFilter
282 };
283
284 modules.filterValidation =
285 {
286 parseFilter(text)
263 { 287 {
264 if (params.filterError) 288 if (params.filterError)
265 return {error: "Invalid filter"}; 289 return {error: "Invalid filter"};
266 return {filter: modules.filterClasses.Filter.fromText(text)}; 290 return {filter: modules.filterClasses.Filter.fromText(text)};
267 }, 291 },
268 parseFilters: function(text) 292 parseFilters(text)
269 { 293 {
270 if (params.filterError) 294 if (params.filterError)
271 return {errors: ["Invalid filter"]}; 295 return {errors: ["Invalid filter"]};
272 return { 296 return {
273 filters: text.split("\n") 297 filters: text.split("\n")
274 .filter(function(filter) {return !!filter;}) 298 .filter(filter => !!filter)
275 .map(modules.filterClasses.Filter.fromText), 299 .map(modules.filterClasses.Filter.fromText),
276 errors: [] 300 errors: []
277 }; 301 };
278 } 302 }
279 }; 303 };
280 304
281 modules.synchronizer = { 305 modules.synchronizer = {
282 Synchronizer: { 306 Synchronizer: {
283 _downloading: false, 307 _downloading: false,
284 execute: function(subscription, manual) 308 execute(subscription, manual)
285 { 309 {
286 modules.synchronizer.Synchronizer._downloading = true; 310 modules.synchronizer.Synchronizer._downloading = true;
287 modules.filterNotifier.FilterNotifier.emit( 311 modules.filterNotifier.FilterNotifier.emit(
288 "subscription.downloading", subscription 312 "subscription.downloading", subscription
289 ); 313 );
290 setTimeout(function() 314 setTimeout(() =>
291 { 315 {
292 modules.synchronizer.Synchronizer._downloading = false; 316 modules.synchronizer.Synchronizer._downloading = false;
293 subscription.lastDownload = Date.now() / 1000; 317 subscription.lastDownload = Date.now() / 1000;
294 }, 500); 318 }, 500);
295 }, 319 },
296 isExecuting: function(url) 320 isExecuting(url)
297 { 321 {
298 return modules.synchronizer.Synchronizer._downloading; 322 return modules.synchronizer.Synchronizer._downloading;
299 } 323 }
300 } 324 }
301 }; 325 };
302 326
303 modules.matcher = { 327 modules.matcher = {
304 defaultMatcher: { 328 defaultMatcher: {
305 matchesAny: function(url, requestType, docDomain, thirdParty) 329 matchesAny(url, requestType, docDomain, thirdParty)
306 { 330 {
307 var blocked = params.blockedURLs.split(","); 331 let blocked = params.blockedURLs.split(",");
308 if (blocked.indexOf(url) >= 0) 332 if (blocked.indexOf(url) >= 0)
309 return new modules.filterClasses.BlockingFilter(); 333 return new modules.filterClasses.BlockingFilter();
310 else 334 return null;
311 return null;
312 } 335 }
313 } 336 }
314 }; 337 };
315 338
316 modules.elemHideEmulation = { 339 modules.elemHideEmulation = {
317 ElemHideEmulation: {} 340 ElemHideEmulation: {}
318 }; 341 };
319 342
320 modules.filterNotifier = { 343 modules.filterNotifier = {
321 FilterNotifier: new EventEmitter() 344 FilterNotifier: new EventEmitter()
(...skipping 15 matching lines...) Expand all
337 360
338 modules.messaging = { 361 modules.messaging = {
339 port: new EventEmitter() 362 port: new EventEmitter()
340 }; 363 };
341 364
342 window.addEventListener("message", event => 365 window.addEventListener("message", event =>
343 { 366 {
344 if (event.data.type != "message") 367 if (event.data.type != "message")
345 return; 368 return;
346 let message = event.data.payload; 369 let message = event.data.payload;
347 let messageId = event.data.messageId; 370 let {messageId} = event.data;
348 let sender = { 371 let sender = {
349 page: new ext.Page(event.source) 372 page: new ext.Page(event.source)
350 }; 373 };
351 374
352 let listeners = modules.messaging.port._listeners[message.type]; 375 let listeners = modules.messaging.port._listeners[message.type];
353 if (!listeners) 376 if (!listeners)
354 return; 377 return;
355 378
356 function reply(message) 379 function reply(responseMessage)
357 { 380 {
358 event.source.postMessage({ 381 event.source.postMessage({
359 type: "response", 382 type: "response",
360 messageId: messageId, 383 messageId,
361 payload: message 384 payload: responseMessage
362 }, "*"); 385 }, "*");
363 } 386 }
364 387
365 for (let listener of listeners) 388 for (let listener of listeners)
366 { 389 {
367 let response = listener(message, sender); 390 let response = listener(message, sender);
368 if (response && typeof response.then == "function") 391 if (response && typeof response.then == "function")
369 { 392 {
370 response.then( 393 response.then(
371 reply, 394 reply,
372 reason => { 395 reason =>
396 {
373 console.error(reason); 397 console.error(reason);
374 reply(undefined); 398 reply(undefined);
375 } 399 }
376 ); 400 );
377 } 401 }
378 else if (typeof response != "undefined") 402 else if (typeof response != "undefined")
379 {
380 reply(response); 403 reply(response);
381 }
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
« no previous file with comments | « README.md ('k') | common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld