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

Side by Side Diff: options.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Fixed typo with shadowRoot getter Created March 14, 2017, 10:28 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 /* global $, i18n, i18nTimeDateStrings */
19
18 "use strict"; 20 "use strict";
19 21
20 /** 22 /**
21 * Creates a wrapping function used to conveniently send a type of message. 23 * Creates a wrapping function used to conveniently send a type of message.
22 * 24 *
23 * @param {Object} baseMessage The part of the message that's always sent 25 * @param {Object} baseMessage The part of the message that's always sent
24 * @param {..string} paramKeys Any message keys that have dynamic values. The 26 * @param {...string} paramKeys Any message keys that have dynamic values. The
25 * returned function will take the corresponding 27 * returned function will take the corresponding
26 * values as arguments. 28 * values as arguments.
27 * @return The generated messaging function, optionally taking any values as 29 * @return {function} The generated messaging function, optionally
28 * specified by the paramKeys and finally an optional callback. 30 * taking any values as specified by the paramKeys
29 * (Although the value arguments are optional their index must be 31 * and finally an optional callback. (Although the
30 * maintained. E.g. if you omit the first value you must omit the 32 * value arguments are optional their index must be
31 * second too.) 33 * maintained. E.g. if you omit the first value you
34 * must omit the second too.)
32 */ 35 */
33 function wrapper(baseMessage /* , [paramKeys] */) 36 function wrapper(baseMessage, ...paramKeys)
34 { 37 {
35 let paramKeys = []; 38 return function(...paramValues /* , callback */)
Wladimir Palant 2017/03/14 13:03:30 I wonder why this isn't using promises. Not someth
kzar 2017/03/15 04:57:53 Acknowledged.
36 for (let i = 1; i < arguments.length; i++)
37 paramKeys.push(arguments[i]);
38
39 return function(/* [paramValues], callback */)
40 { 39 {
41 let message = Object.create(null); 40 let message = Object.create(null);
42 for (let key in baseMessage) 41 for (let key in baseMessage)
42 {
43 if (baseMessage.hasOwnProperty(key)) 43 if (baseMessage.hasOwnProperty(key))
44 message[key] = baseMessage[key]; 44 message[key] = baseMessage[key];
45 }
45 46
46 let paramValues = [];
47 let callback; 47 let callback;
48 48
49 if (arguments.length > 0) 49 if (paramValues.length > 0)
50 { 50 {
51 let lastArg = arguments[arguments.length - 1]; 51 let lastArg = paramValues[paramValues.length - 1];
52 if (typeof lastArg == "function") 52 if (typeof lastArg == "function")
53 callback = lastArg; 53 callback = lastArg;
54 54
55 for (let i = 0; i < arguments.length - (callback ? 1 : 0); i++) 55 for (let i = 0; i < paramValues.length - (callback ? 1 : 0); i++)
56 message[paramKeys[i]] = arguments[i]; 56 message[paramKeys[i]] = paramValues[i];
57 } 57 }
58 58
59 ext.backgroundPage.sendMessage(message, callback); 59 ext.backgroundPage.sendMessage(message, callback);
60 }; 60 };
61 } 61 }
62 62
63 const getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); 63 const getDocLink = wrapper({type: "app.get", what: "doclink"}, "link");
64 const getInfo = wrapper({type: "app.get"}, "what"); 64 const getInfo = wrapper({type: "app.get"}, "what");
65 const getPref = wrapper({type: "prefs.get"}, "key"); 65 const getPref = wrapper({type: "prefs.get"}, "key");
66 const togglePref = wrapper({type: "prefs.toggle"}, "key"); 66 const togglePref = wrapper({type: "prefs.toggle"}, "key");
67 const getSubscriptions = wrapper({type: "subscriptions.get"}, 67 const getSubscriptions = wrapper({type: "subscriptions.get"},
68 "downloadable", "special"); 68 "downloadable", "special");
69 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); 69 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url");
70 const addSubscription = wrapper({type: "subscriptions.add"}, 70 const addSubscription = wrapper({type: "subscriptions.add"},
71 "url", "title", "homepage"); 71 "url", "title", "homepage");
72 const toggleSubscription = wrapper({type: "subscriptions.toggle"}, 72 const toggleSubscription = wrapper({type: "subscriptions.toggle"},
73 "url", "keepInstalled"); 73 "url", "keepInstalled");
74 const updateSubscription = wrapper({type: "subscriptions.update"}, "url"); 74 const updateSubscription = wrapper({type: "subscriptions.update"}, "url");
75 const importRawFilters = wrapper({type: "filters.importRaw"}, 75 const importRawFilters = wrapper({type: "filters.importRaw"},
76 "text", "removeExisting"); 76 "text", "removeExisting");
77 const addFilter = wrapper({type: "filters.add"}, "text"); 77 const addFilter = wrapper({type: "filters.add"}, "text");
78 const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); 78 const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl");
79 const removeFilter = wrapper({type: "filters.remove"}, "text"); 79 const removeFilter = wrapper({type: "filters.remove"}, "text");
80 80
81 const whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; 81 const whitelistedDomainRegexp = /^@@\|\|([^/:]+)\^\$document$/;
82 const statusMessages = new Map([
83 ["synchronize_invalid_url",
84 "filters_subscription_lastDownload_invalidURL"],
85 ["synchronize_connection_error",
86 "filters_subscription_lastDownload_connectionError"],
87 ["synchronize_invalid_data",
88 "filters_subscription_lastDownload_invalidData"],
89 ["synchronize_checksum_mismatch",
90 "filters_subscription_lastDownload_checksumMismatch"]
91 ]);
92
82 let delayedSubscriptionSelection = null; 93 let delayedSubscriptionSelection = null;
83
84 let acceptableAdsUrl; 94 let acceptableAdsUrl;
85 95
86 // Loads options from localStorage and sets UI elements accordingly 96 // Loads options from localStorage and sets UI elements accordingly
87 function loadOptions() 97 function loadOptions()
88 { 98 {
89 // Set page title to i18n version of "Adblock Plus Options" 99 // Set page title to i18n version of "Adblock Plus Options"
90 document.title = i18n.getMessage("options"); 100 document.title = i18n.getMessage("options");
91 101
92 // Set links 102 // Set links
93 getPref("subscriptions_exceptionsurl", url => 103 getPref("subscriptions_exceptionsurl", url =>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Popuplate option checkboxes 150 // Popuplate option checkboxes
141 initCheckbox("shouldShowBlockElementMenu"); 151 initCheckbox("shouldShowBlockElementMenu");
142 initCheckbox("show_devtools_panel"); 152 initCheckbox("show_devtools_panel");
143 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); 153 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories");
144 154
145 getInfo("features", features => 155 getInfo("features", features =>
146 { 156 {
147 if (!features.devToolsPanel) 157 if (!features.devToolsPanel)
148 document.getElementById("showDevtoolsPanelContainer").hidden = true; 158 document.getElementById("showDevtoolsPanelContainer").hidden = true;
149 }); 159 });
150 getPref("notifications_showui", notifications_showui => 160 getPref("notifications_showui", showNotificationsUI =>
151 { 161 {
152 if (!notifications_showui) 162 if (!showNotificationsUI)
153 document.getElementById("shouldShowNotificationsContainer").hidden = true; 163 document.getElementById("shouldShowNotificationsContainer").hidden = true;
154 }); 164 });
155 165
156 // Register listeners in the background message responder 166 // Register listeners in the background message responder
157 ext.backgroundPage.sendMessage({ 167 ext.backgroundPage.sendMessage({
158 type: "app.listen", 168 type: "app.listen",
159 filter: ["addSubscription", "focusSection"] 169 filter: ["addSubscription", "focusSection"]
160 }); 170 });
161 ext.backgroundPage.sendMessage( 171 ext.backgroundPage.sendMessage({
162 {
163 type: "filters.listen", 172 type: "filters.listen",
164 filter: ["added", "loaded", "removed"] 173 filter: ["added", "loaded", "removed"]
165 }); 174 });
166 ext.backgroundPage.sendMessage( 175 ext.backgroundPage.sendMessage({
167 {
168 type: "prefs.listen", 176 type: "prefs.listen",
169 filter: ["notifications_ignoredcategories", "notifications_showui", 177 filter: ["notifications_ignoredcategories", "notifications_showui",
170 "show_devtools_panel", "shouldShowBlockElementMenu"] 178 "show_devtools_panel", "shouldShowBlockElementMenu"]
171 }); 179 });
172 ext.backgroundPage.sendMessage( 180 ext.backgroundPage.sendMessage({
173 {
174 type: "subscriptions.listen", 181 type: "subscriptions.listen",
175 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 182 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
176 "title", "downloadStatus", "downloading"] 183 "title", "downloadStatus", "downloading"]
177 }); 184 });
178 185
179 // Load recommended subscriptions 186 // Load recommended subscriptions
180 loadRecommendations(); 187 loadRecommendations();
181 188
182 // Show user's filters 189 // Show user's filters
183 reloadFilters(); 190 reloadFilters();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 313
307 let option = new Option(); 314 let option = new Option();
308 let label = i18n.getMessage("filters_addSubscriptionOther_label"); 315 let label = i18n.getMessage("filters_addSubscriptionOther_label");
309 option.text = label + "\u2026"; 316 option.text = label + "\u2026";
310 option._data = null; 317 option._data = null;
311 list.appendChild(option); 318 list.appendChild(option);
312 319
313 list.selectedIndex = selectedIndex; 320 list.selectedIndex = selectedIndex;
314 321
315 if (delayedSubscriptionSelection) 322 if (delayedSubscriptionSelection)
316 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); 323 startSubscriptionSelection(...delayedSubscriptionSelection);
317 }); 324 });
318 } 325 }
319 326
320 function startSubscriptionSelection(title, url) 327 function startSubscriptionSelection(title, url)
321 { 328 {
322 let list = document.getElementById("subscriptionSelector"); 329 let list = document.getElementById("subscriptionSelector");
323 if (list.length == 0) 330 if (list.length == 0)
324 { 331 {
325 delayedSubscriptionSelection = [title, url]; 332 delayedSubscriptionSelection = [title, url];
326 return; 333 return;
(...skipping 27 matching lines...) Expand all
354 } 361 }
355 362
356 function addSubscriptionClicked() 363 function addSubscriptionClicked()
357 { 364 {
358 let list = document.getElementById("subscriptionSelector"); 365 let list = document.getElementById("subscriptionSelector");
359 let data = list.options[list.selectedIndex]._data; 366 let data = list.options[list.selectedIndex]._data;
360 if (data) 367 if (data)
361 addSubscription(data.url, data.title, data.homepage); 368 addSubscription(data.url, data.title, data.homepage);
362 else 369 else
363 { 370 {
364 let url = document.getElementById("customSubscriptionLocation").value.trim() ; 371 let url = document.getElementById("customSubscriptionLocation")
372 .value.trim();
Wladimir Palant 2017/03/14 13:03:30 Nit: align dots maybe?
kzar 2017/03/15 04:57:53 Done.
365 if (!/^https?:/i.test(url)) 373 if (!/^https?:/i.test(url))
366 { 374 {
367 alert(i18n.getMessage("global_subscription_invalid_location")); 375 alert(i18n.getMessage("global_subscription_invalid_location"));
368 $("#customSubscriptionLocation").focus(); 376 $("#customSubscriptionLocation").focus();
369 return; 377 return;
370 } 378 }
371 379
372 let title = document.getElementById("customSubscriptionTitle").value.trim(); 380 let title = document.getElementById("customSubscriptionTitle").value.trim();
373 if (!title) 381 if (!title)
374 title = url; 382 title = url;
375 383
376 addSubscription(url, title, null); 384 addSubscription(url, title, null);
377 } 385 }
378 386
379 $("#addSubscriptionContainer").hide(); 387 $("#addSubscriptionContainer").hide();
380 $("#customSubscriptionContainer").hide(); 388 $("#customSubscriptionContainer").hide();
381 $("#addSubscriptionButton").show(); 389 $("#addSubscriptionButton").show();
382 } 390 }
383 391
384 function toggleAcceptableAds() 392 function toggleAcceptableAds()
385 { 393 {
386 toggleSubscription(acceptableAdsUrl, true); 394 toggleSubscription(acceptableAdsUrl, true);
387 } 395 }
388 396
389 function findSubscriptionElement(subscription) 397 function findSubscriptionElement(subscription)
390 { 398 {
391 for (let child of document.getElementById("filterLists").childNodes) 399 for (let child of document.getElementById("filterLists").childNodes)
400 {
392 if (child._subscription.url == subscription.url) 401 if (child._subscription.url == subscription.url)
393 return child; 402 return child;
403 }
394 return null; 404 return null;
395 } 405 }
396 406
397 function updateSubscriptionInfo(element, subscription) 407 function updateSubscriptionInfo(element, subscription)
398 { 408 {
399 if (subscription) 409 if (subscription)
400 element._subscription = subscription; 410 element._subscription = subscription;
401 else 411 else
402 subscription = element._subscription; 412 subscription = element._subscription;
403 413
404 let title = element.getElementsByClassName("subscriptionTitle")[0]; 414 let title = element.getElementsByClassName("subscriptionTitle")[0];
405 title.textContent = subscription.title; 415 title.textContent = subscription.title;
406 title.setAttribute("title", subscription.url); 416 title.setAttribute("title", subscription.url);
407 if (subscription.homepage) 417 if (subscription.homepage)
408 title.href = subscription.homepage; 418 title.href = subscription.homepage;
409 else 419 else
410 title.href = subscription.url; 420 title.href = subscription.url;
411 421
412 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; 422 let enabled = element.getElementsByClassName("subscriptionEnabled")[0];
413 enabled.checked = !subscription.disabled; 423 enabled.checked = !subscription.disabled;
414 424
415 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; 425 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0];
416 lastUpdate.classList.remove("error"); 426 lastUpdate.classList.remove("error");
417 427
418 let downloadStatus = subscription.downloadStatus; 428 let {downloadStatus} = subscription;
419 if (subscription.isDownloading) 429 if (subscription.isDownloading)
420 { 430 {
421 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_ inProgress"); 431 lastUpdate.textContent = i18n.getMessage(
432 "filters_subscription_lastDownload_inProgress"
433 );
422 } 434 }
423 else if (downloadStatus && downloadStatus != "synchronize_ok") 435 else if (downloadStatus && downloadStatus != "synchronize_ok")
424 { 436 {
425 let map = 437 if (statusMessages.has(downloadStatus))
426 { 438 {
427 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" , 439 lastUpdate.textContent = i18n.getMessage(
428 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError", 440 statusMessages.get(downloadStatus)
429 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a", 441 );
430 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch" 442 }
431 }; 443 else
432 if (downloadStatus in map) 444 lastUpdate.textContent = downloadStatus;
433 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); 445 lastUpdate.classList.add("error");
434 else
435 lastUpdate.textContent = downloadStatus;
436 lastUpdate.classList.add("error");
437 } 446 }
438 else if (subscription.lastDownload > 0) 447 else if (subscription.lastDownload > 0)
439 { 448 {
440 let timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); 449 let timeDate = i18nTimeDateStrings(subscription.lastDownload * 1000);
441 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); 450 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today");
442 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); 451 lastUpdate.textContent = i18n.getMessage(messageID, timeDate);
443 } 452 }
444 } 453 }
445 454
446 function onSubscriptionMessage(action, subscription) 455 function onSubscriptionMessage(action, subscription)
447 { 456 {
448 let element = findSubscriptionElement(subscription); 457 let element = findSubscriptionElement(subscription);
449 458
450 switch (action) 459 switch (action)
(...skipping 22 matching lines...) Expand all
473 element.parentNode.removeChild(element); 482 element.parentNode.removeChild(element);
474 break; 483 break;
475 } 484 }
476 } 485 }
477 486
478 function onPrefMessage(key, value) 487 function onPrefMessage(key, value)
479 { 488 {
480 switch (key) 489 switch (key)
481 { 490 {
482 case "notifications_showui": 491 case "notifications_showui":
483 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; 492 document.getElementById(
493 "shouldShowNotificationsContainer"
494 ).hidden = !value;
484 return; 495 return;
485 case "notifications_ignoredcategories": 496 case "notifications_ignoredcategories":
486 key = "shouldShowNotifications"; 497 key = "shouldShowNotifications";
487 value = value.indexOf("*") == -1; 498 value = value.indexOf("*") == -1;
488 break; 499 break;
489 } 500 }
490 let checkbox = document.getElementById(key); 501 let checkbox = document.getElementById(key);
491 if (checkbox) 502 if (checkbox)
492 checkbox.checked = value; 503 checkbox.checked = value;
493 } 504 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 let list = document.getElementById(boxId); 541 let list = document.getElementById(boxId);
531 let selector = "option[value=" + CSS.escape(text) + "]"; 542 let selector = "option[value=" + CSS.escape(text) + "]";
532 for (let option of list.querySelectorAll(selector)) 543 for (let option of list.querySelectorAll(selector))
533 list.removeChild(option); 544 list.removeChild(option);
534 } 545 }
535 546
536 function addWhitelistDomain(event) 547 function addWhitelistDomain(event)
537 { 548 {
538 event.preventDefault(); 549 event.preventDefault();
539 550
540 let domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , ""); 551 let domain = document.getElementById(
552 "newWhitelistDomain"
553 ).value.replace(/\s/g, "");
541 document.getElementById("newWhitelistDomain").value = ""; 554 document.getElementById("newWhitelistDomain").value = "";
542 if (!domain) 555 if (!domain)
543 return; 556 return;
544 557
545 let filterText = "@@||" + domain + "^$document"; 558 let filterText = "@@||" + domain + "^$document";
546 addFilter(filterText); 559 addFilter(filterText);
547 } 560 }
548 561
549 // Adds filter text that user typed to the selection box 562 // Adds filter text that user typed to the selection box
550 function addTypedFilter(event) 563 function addTypedFilter(event)
551 { 564 {
552 event.preventDefault(); 565 event.preventDefault();
553 566
554 let element = document.getElementById("newFilter"); 567 let element = document.getElementById("newFilter");
555 addFilter(element.value, errors => 568 addFilter(element.value, errors =>
556 { 569 {
557 if (errors.length > 0) 570 if (errors.length > 0)
558 alert(errors.join("\n")); 571 alert(errors.join("\n"));
559 else 572 else
560 element.value = ""; 573 element.value = "";
561 }); 574 });
562 } 575 }
563 576
564 // Removes currently selected whitelisted domains 577 // Removes currently selected whitelisted domains
565 function removeSelectedExcludedDomain(event) 578 function removeSelectedExcludedDomain(event)
566 { 579 {
567 event.preventDefault(); 580 event.preventDefault();
568 let remove = []; 581 let remove = [];
569 for (let option of document.getElementById("excludedDomainsBox").options) 582 for (let option of document.getElementById("excludedDomainsBox").options)
583 {
570 if (option.selected) 584 if (option.selected)
571 remove.push(option.value); 585 remove.push(option.value);
586 }
572 if (!remove.length) 587 if (!remove.length)
573 return; 588 return;
574 589
575 for (let domain of remove) 590 for (let domain of remove)
576 removeFilter("@@||" + domain + "^$document"); 591 removeFilter("@@||" + domain + "^$document");
577 } 592 }
578 593
579 // Removes all currently selected filters 594 // Removes all currently selected filters
580 function removeSelectedFilters(event) 595 function removeSelectedFilters(event)
581 { 596 {
582 event.preventDefault(); 597 event.preventDefault();
583 for (let option of document.querySelectorAll("#userFiltersBox > option:checked ")) 598 let options = document.querySelectorAll("#userFiltersBox > option:checked");
599 for (let option of options)
584 removeFilter(option.value); 600 removeFilter(option.value);
585 } 601 }
586 602
587 // Shows raw filters box and fills it with the current user filters 603 // Shows raw filters box and fills it with the current user filters
588 function toggleFiltersInRawFormat(event) 604 function toggleFiltersInRawFormat(event)
589 { 605 {
590 event.preventDefault(); 606 event.preventDefault();
591 607
592 let rawFilters = document.getElementById("rawFilters"); 608 let rawFilters = document.getElementById("rawFilters");
593 let filters = []; 609 let filters = [];
594 610
595 if (rawFilters.style.display != "table-row") 611 if (rawFilters.style.display != "table-row")
596 { 612 {
597 rawFilters.style.display = "table-row"; 613 rawFilters.style.display = "table-row";
598 for (let option of document.getElementById("userFiltersBox").options) 614 for (let option of document.getElementById("userFiltersBox").options)
599 filters.push(option.value); 615 filters.push(option.value);
600 } 616 }
601 else 617 else
602 {
603 rawFilters.style.display = "none"; 618 rawFilters.style.display = "none";
604 }
605 619
606 document.getElementById("rawFiltersText").value = filters.join("\n"); 620 document.getElementById("rawFiltersText").value = filters.join("\n");
607 } 621 }
608 622
609 // Imports filters in the raw text box 623 // Imports filters in the raw text box
610 function importRawFiltersText() 624 function importRawFiltersText()
611 { 625 {
612 let text = document.getElementById("rawFiltersText").value; 626 let text = document.getElementById("rawFiltersText").value;
613 627
614 importRawFilters(text, true, errors => 628 importRawFilters(text, true, errors =>
(...skipping 13 matching lines...) Expand all
628 } 642 }
629 643
630 // Adds a subscription entry to the UI. 644 // Adds a subscription entry to the UI.
631 function addSubscriptionEntry(subscription) 645 function addSubscriptionEntry(subscription)
632 { 646 {
633 let template = document.getElementById("subscriptionTemplate"); 647 let template = document.getElementById("subscriptionTemplate");
634 let element = template.cloneNode(true); 648 let element = template.cloneNode(true);
635 element.removeAttribute("id"); 649 element.removeAttribute("id");
636 element._subscription = subscription; 650 element._subscription = subscription;
637 651
638 let removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0]; 652 let removeButton = element.getElementsByClassName(
653 "subscriptionRemoveButton"
654 )[0];
639 removeButton.setAttribute("title", removeButton.textContent); 655 removeButton.setAttribute("title", removeButton.textContent);
640 removeButton.textContent = "\xD7"; 656 removeButton.textContent = "\xD7";
641 removeButton.addEventListener("click", () => 657 removeButton.addEventListener("click", () =>
642 { 658 {
643 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) 659 if (!confirm(i18n.getMessage("global_remove_subscription_warning")))
644 return; 660 return;
645 661
646 removeSubscription(subscription.url); 662 removeSubscription(subscription.url);
647 }, false); 663 }, false);
648 664
649 getPref("additional_subscriptions", additionalSubscriptions => 665 getPref("additional_subscriptions", additionalSubscriptions =>
650 { 666 {
651 if (additionalSubscriptions.indexOf(subscription.url) != -1) 667 if (additionalSubscriptions.indexOf(subscription.url) != -1)
652 removeButton.style.visibility = "hidden"; 668 removeButton.style.visibility = "hidden";
653 }); 669 });
654 670
655 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; 671 let enabled = element.getElementsByClassName("subscriptionEnabled")[0];
656 enabled.addEventListener("click", () => 672 enabled.addEventListener("click", () =>
657 { 673 {
658 subscription.disabled = !subscription.disabled; 674 subscription.disabled = !subscription.disabled;
659 toggleSubscription(subscription.url, true); 675 toggleSubscription(subscription.url, true);
660 }, false); 676 }, false);
661 677
662 updateSubscriptionInfo(element); 678 updateSubscriptionInfo(element);
663 679
664 document.getElementById("filterLists").appendChild(element); 680 document.getElementById("filterLists").appendChild(element);
665 } 681 }
666 682
667 function setLinks(id) 683 function setLinks(id, ...args)
668 { 684 {
669 let element = document.getElementById(id); 685 let element = document.getElementById(id);
670 if (!element) 686 if (!element)
671 return; 687 return;
672 688
673 let links = element.getElementsByTagName("a"); 689 let links = element.getElementsByTagName("a");
674 for (let i = 0; i < links.length; i++) 690 for (let i = 0; i < links.length; i++)
675 { 691 {
676 if (typeof arguments[i + 1] == "string") 692 if (typeof args[i] == "string")
677 { 693 {
678 links[i].href = arguments[i + 1]; 694 links[i].href = args[i];
679 links[i].setAttribute("target", "_blank"); 695 links[i].setAttribute("target", "_blank");
680 } 696 }
681 else if (typeof arguments[i + 1] == "function") 697 else if (typeof args[i] == "function")
682 { 698 {
683 links[i].href = "javascript:void(0);"; 699 links[i].href = "javascript:void(0);";
684 links[i].addEventListener("click", arguments[i + 1], false); 700 links[i].addEventListener("click", args[i], false);
685 } 701 }
686 } 702 }
687 } 703 }
688 704
689 ext.onMessage.addListener(message => 705 ext.onMessage.addListener(message =>
690 { 706 {
691 switch (message.type) 707 switch (message.type)
692 { 708 {
693 case "app.respond": 709 case "app.respond":
694 switch (message.action) 710 switch (message.action)
(...skipping 26 matching lines...) Expand all
721 onFilterMessage(message.action, message.args[0]); 737 onFilterMessage(message.action, message.args[0]);
722 break; 738 break;
723 case "prefs.respond": 739 case "prefs.respond":
724 onPrefMessage(message.action, message.args[0]); 740 onPrefMessage(message.action, message.args[0]);
725 break; 741 break;
726 case "subscriptions.respond": 742 case "subscriptions.respond":
727 onSubscriptionMessage(message.action, message.args[0]); 743 onSubscriptionMessage(message.action, message.args[0]);
728 break; 744 break;
729 } 745 }
730 }); 746 });
OLDNEW

Powered by Google App Engine
This is Rietveld