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

Delta Between Two Patch Sets: background.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Left Patch Set: Fix regressions with the new options page Created March 1, 2017, 8:25 a.m.
Right Patch Set: Avoid violating operator-linebreak rule Created March 15, 2017, 4:43 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « README.md ('k') | common.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 "use strict"; 18 "use strict";
19 19
20 (function()
20 { 21 {
21 function EventEmitter() 22 function EventEmitter()
22 { 23 {
23 this._listeners = Object.create(null); 24 this._listeners = Object.create(null);
24 } 25 }
25 EventEmitter.prototype = { 26 EventEmitter.prototype = {
26 on(name, listener) 27 on(name, listener)
27 { 28 {
28 if (name in this._listeners) 29 if (name in this._listeners)
29 this._listeners[name].push(listener); 30 this._listeners[name].push(listener);
(...skipping 18 matching lines...) Expand all
48 for (let listener of listeners) 49 for (let listener of listeners)
49 listener(...args); 50 listener(...args);
50 } 51 }
51 } 52 }
52 }; 53 };
53 54
54 function updateFromURL(data) 55 function updateFromURL(data)
55 { 56 {
56 if (window.location.search) 57 if (window.location.search)
57 { 58 {
58 for (let param of window.location.search.substr(1).split("&")) 59 let params = window.location.search.substr(1).split("&");
Thomas Greiner 2017/03/01 17:39:32 Detail: Putting that long statement within the for
kzar 2017/03/07 12:48:31 Done.
60
61 for (let param of params)
59 { 62 {
60 let parts = param.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 let params = { 70 let params = {
68 blockedURLs: "", 71 blockedURLs: "",
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return subscriptions; 201 return subscriptions;
199 }, 202 },
200 203
201 get knownSubscriptions() 204 get knownSubscriptions()
202 { 205 {
203 return knownSubscriptions; 206 return knownSubscriptions;
204 }, 207 },
205 208
206 addSubscription(subscription) 209 addSubscription(subscription)
207 { 210 {
208 let {fromURL} = modules.subscriptionClasses.Subscription; 211 let {fromURL} = Subscription;
Thomas Greiner 2017/03/01 17:39:34 Detail: You can now refer to `Subscription` direct
kzar 2017/03/07 12:48:31 Done.
209 let {FilterStorage} = modules.filterStorage; 212 let {FilterStorage} = modules.filterStorage;
210 213
211 if (!(subscription.url in FilterStorage.knownSubscriptions)) 214 if (!(subscription.url in FilterStorage.knownSubscriptions))
212 { 215 {
213 knownSubscriptions[subscription.url] = fromURL(subscription.url); 216 knownSubscriptions[subscription.url] = fromURL(subscription.url);
214 modules.filterNotifier.FilterNotifier.emit("subscription.added", 217 modules.filterNotifier.FilterNotifier.emit("subscription.added",
215 subscription); 218 subscription);
216 } 219 }
217 }, 220 },
218 221
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 256 }
254 } 257 }
255 } 258 }
256 }; 259 };
257 260
258 function Filter(text) 261 function Filter(text)
259 { 262 {
260 this.text = text; 263 this.text = text;
261 this.disabled = false; 264 this.disabled = false;
262 } 265 }
263 Filter.fromText = text => 266 Filter.fromText = (text) => new Filter(text);
Thomas Greiner 2017/03/01 17:39:34 Detail: Mind writing this as follows? Filter.from
kzar 2017/03/07 12:48:30 Done.
264 {
265 return new modules.filterClasses.Filter(text);
266 };
267 267
268 function BlockingFilter() 268 function BlockingFilter()
269 { 269 {
270 } 270 }
271 271
272 function RegExpFilter() 272 function RegExpFilter()
273 { 273 {
274 } 274 }
275 RegExpFilter.typeMap = Object.create(null); 275 RegExpFilter.typeMap = Object.create(null);
276 276
(...skipping 10 matching lines...) Expand all
287 if (params.filterError) 287 if (params.filterError)
288 return {error: "Invalid filter"}; 288 return {error: "Invalid filter"};
289 return {filter: modules.filterClasses.Filter.fromText(text)}; 289 return {filter: modules.filterClasses.Filter.fromText(text)};
290 }, 290 },
291 parseFilters(text) 291 parseFilters(text)
292 { 292 {
293 if (params.filterError) 293 if (params.filterError)
294 return {errors: ["Invalid filter"]}; 294 return {errors: ["Invalid filter"]};
295 return { 295 return {
296 filters: text.split("\n") 296 filters: text.split("\n")
297 .filter(filter => !!filter) 297 .filter((filter) => !!filter)
298 .map(modules.filterClasses.Filter.fromText), 298 .map(modules.filterClasses.Filter.fromText),
299 errors: [] 299 errors: []
300 }; 300 };
301 } 301 }
302 }; 302 };
303 303
304 modules.synchronizer = { 304 modules.synchronizer = {
305 Synchronizer: { 305 Synchronizer: {
306 _downloading: false, 306 _downloading: false,
307 execute(subscription, manual) 307 execute(subscription, manual)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 updateFromURL(modules.info); 354 updateFromURL(modules.info);
355 355
356 modules.subscriptionInit = { 356 modules.subscriptionInit = {
357 reinitialized: params.filterlistsReinitialized 357 reinitialized: params.filterlistsReinitialized
358 }; 358 };
359 359
360 modules.messaging = { 360 modules.messaging = {
361 port: new EventEmitter() 361 port: new EventEmitter()
362 }; 362 };
363 363
364 window.addEventListener("message", event => 364 window.addEventListener("message", (event) =>
365 { 365 {
366 if (event.data.type != "message") 366 if (event.data.type != "message")
367 return; 367 return;
368 let message = event.data.payload; 368 let message = event.data.payload;
369 let {messageId} = event.data; 369 let {messageId} = event.data;
370 let sender = { 370 let sender = {
371 page: new ext.Page(event.source) 371 page: new ext.Page(event.source)
372 }; 372 };
373 373
374 let listeners = modules.messaging.port._listeners[message.type]; 374 let listeners = modules.messaging.port._listeners[message.type];
375 if (!listeners) 375 if (!listeners)
376 return; 376 return;
377 377
378 function reply(responseMessage) 378 function reply(responseMessage)
379 { 379 {
380 event.source.postMessage({ 380 event.source.postMessage({
381 type: "response", 381 type: "response",
382 messageId, 382 messageId,
383 payload: responseMessage 383 payload: responseMessage
384 }, "*"); 384 }, "*");
385 } 385 }
386 386
387 for (let listener of listeners) 387 for (let listener of listeners)
388 { 388 {
389 let response = listener(message, sender); 389 let response = listener(message, sender);
390 if (response && typeof response.then == "function") 390 if (response && typeof response.then == "function")
391 { 391 {
392 response.then( 392 response.then(
393 reply, 393 reply,
394 reason => 394 (reason) =>
395 { 395 {
396 console.error(reason); 396 console.error(reason);
397 reply(undefined); 397 reply(undefined);
398 } 398 }
399 ); 399 );
400 } 400 }
401 else if (typeof response != "undefined") 401 else if (typeof response != "undefined")
402 {
402 reply(response); 403 reply(response);
404 }
403 } 405 }
404 }); 406 });
405 407
406 window.Services = { 408 window.Services = {
407 vc: { 409 vc: {
408 compare(v1, v2) 410 compare(v1, v2)
409 { 411 {
410 return parseFloat(v1) - parseFloat(v2); 412 return parseFloat(v1) - parseFloat(v2);
411 } 413 }
412 } 414 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 payload: { 463 payload: {
462 title: "Custom subscription", 464 title: "Custom subscription",
463 url: "http://example.com/custom.txt", 465 url: "http://example.com/custom.txt",
464 confirm: true, 466 confirm: true,
465 type: "subscriptions.add" 467 type: "subscriptions.add"
466 } 468 }
467 }, "*"); 469 }, "*");
468 }, 1000); 470 }, 1000);
469 } 471 }
470 472
471 ext.devtools.onCreated.addListener(panel => 473 ext.devtools.onCreated.addListener((panel) =>
472 { 474 {
473 // blocked request 475 // blocked request
474 panel.sendMessage({ 476 panel.sendMessage({
475 type: "add-record", 477 type: "add-record",
476 request: { 478 request: {
477 url: "http://adserver.example.com/ad_banner.png", 479 url: "http://adserver.example.com/ad_banner.png",
478 type: "IMAGE", 480 type: "IMAGE",
479 docDomain: "example.com" 481 docDomain: "example.com"
480 }, 482 },
481 filter: { 483 filter: {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 docDomain: "example.com" 539 docDomain: "example.com"
538 }, 540 },
539 filter: { 541 filter: {
540 text: "||example.com/some-annoying-popup$popup", 542 text: "||example.com/some-annoying-popup$popup",
541 whitelisted: false, 543 whitelisted: false,
542 userDefined: true, 544 userDefined: true,
543 subscription: null 545 subscription: null
544 } 546 }
545 }); 547 });
546 }); 548 });
547 } 549 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld