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

Delta Between Two Patch Sets: new-options.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Left Patch Set: Addressed the rest of Sebastian's feedback Created March 1, 2017, 5:35 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 | « messageResponder.js ('k') | no next file » | 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
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 385 }
386 else 386 else
387 collections.customFilters.addItem(filter); 387 collections.customFilters.addItem(filter);
388 388
389 filtersMap[filter.text] = filter; 389 filtersMap[filter.text] = filter;
390 } 390 }
391 391
392 function loadRecommendations() 392 function loadRecommendations()
393 { 393 {
394 fetch("subscriptions.xml") 394 fetch("subscriptions.xml")
395 .then(response => 395 .then((response) =>
396 { 396 {
397 return response.text(); 397 return response.text();
398 }) 398 })
399 .then(text => 399 .then((text) =>
400 { 400 {
401 let doc = new DOMParser().parseFromString(text, "application/xml"); 401 let doc = new DOMParser().parseFromString(text, "application/xml");
402 let elements = doc.documentElement.getElementsByTagName("subscription"); 402 let elements = doc.documentElement.getElementsByTagName("subscription");
403 for (let element of elements) 403 for (let element of elements)
404 { 404 {
405 let type = element.getAttribute("type"); 405 let type = element.getAttribute("type");
406 let subscription = { 406 let subscription = {
407 disabled: true, 407 disabled: true,
408 downloadStatus: null, 408 downloadStatus: null,
409 homepage: null, 409 homepage: null,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return element.getAttribute("data-" + dataName); 441 return element.getAttribute("data-" + dataName);
442 } 442 }
443 443
444 element = element.parentElement; 444 element = element.parentElement;
445 } 445 }
446 return null; 446 return null;
447 } 447 }
448 448
449 function sendMessageHandleErrors(message, onSuccess) 449 function sendMessageHandleErrors(message, onSuccess)
450 { 450 {
451 ext.backgroundPage.sendMessage(message, errors => 451 ext.backgroundPage.sendMessage(message, (errors) =>
452 { 452 {
453 if (errors.length > 0) 453 if (errors.length > 0)
454 alert(errors.join("\n")); 454 alert(errors.join("\n"));
455 else if (onSuccess) 455 else if (onSuccess)
456 onSuccess(); 456 onSuccess();
457 }); 457 });
458 } 458 }
459 459
460 function openDocLink(id) 460 function openDocLink(id)
461 { 461 {
462 getDocLink(id, link => 462 getDocLink(id, (link) =>
463 { 463 {
464 if (id == "share-general") 464 if (id == "share-general")
465 openSharePopup(link); 465 openSharePopup(link);
466 else 466 else
467 location.href = link; 467 location.href = link;
468 }); 468 });
469 } 469 }
470 470
471 function switchTab(id) 471 function switchTab(id)
472 { 472 {
473 location.hash = id; 473 location.hash = id;
474 } 474 }
475 475
476 function onClick(e) 476 function onClick(e)
477 { 477 {
478 let context = document.querySelector(".show-context-menu"); 478 let context = document.querySelector(".show-context-menu");
479 if (context) 479 if (context)
480 context.classList.remove("show-context-menu"); 480 context.classList.remove("show-context-menu");
481 481
482 let element = e.target; 482 let element = findParentData(e.target, "action", true);
483 while (element && !element.hasAttribute("data-action")) 483 if (!element)
484 element = element.parentElement; 484 return;
485 485
486 element = findParentData(e.target, "action", true);
487 let actions = element.getAttribute("data-action").split(","); 486 let actions = element.getAttribute("data-action").split(",");
488 for (let action of actions) 487 for (let action of actions)
489 { 488 {
490 switch (action) 489 switch (action)
491 { 490 {
492 case "add-domain-exception": 491 case "add-domain-exception":
493 addWhitelistedDomain(); 492 addWhitelistedDomain();
494 break; 493 break;
495 case "add-predefined-subscription": { 494 case "add-predefined-subscription": {
496 let dialog = E("dialog-content-predefined"); 495 let dialog = E("dialog-content-predefined");
497 let title = dialog.querySelector("h3").textContent; 496 let title = dialog.querySelector("h3").textContent;
498 let url = dialog.querySelector(".url").textContent; 497 let url = dialog.querySelector(".url").textContent;
499 addEnableSubscription(url, title); 498 addEnableSubscription(url, title);
500 closeDialog(); 499 closeDialog();
501 break; 500 break;
502 } 501 }
503 case "cancel-custom-filters": 502 case "cancel-custom-filters":
504 E("custom-filters").classList.remove("mode-edit"); 503 E("custom-filters").classList.remove("mode-edit");
505 break; 504 break;
506 case "cancel-domain-exception": 505 case "cancel-domain-exception":
507 E("whitelisting-textbox").value = ""; 506 E("whitelisting-textbox").value = "";
508 document.querySelector("#whitelisting .controls").classList. 507 document.querySelector("#whitelisting .controls").classList
509 remove("mode-edit"); 508 .remove("mode-edit");
510 break; 509 break;
511 case "close-dialog": 510 case "close-dialog":
512 closeDialog(); 511 closeDialog();
513 break; 512 break;
514 case "edit-custom-filters": 513 case "edit-custom-filters":
515 E("custom-filters").classList.add("mode-edit"); 514 E("custom-filters").classList.add("mode-edit");
516 editCustomFilters(); 515 editCustomFilters();
517 break; 516 break;
518 case "edit-domain-exception": 517 case "edit-domain-exception":
519 document.querySelector("#whitelisting .controls").classList. 518 document.querySelector("#whitelisting .controls").classList
520 add("mode-edit"); 519 .add("mode-edit");
521 E("whitelisting-textbox").focus(); 520 E("whitelisting-textbox").focus();
522 break; 521 break;
523 case "import-subscription": { 522 case "import-subscription": {
524 let url = E("blockingList-textbox").value; 523 let url = E("blockingList-textbox").value;
525 addEnableSubscription(url); 524 addEnableSubscription(url);
526 closeDialog(); 525 closeDialog();
527 break; 526 break;
528 } 527 }
529 case "open-dialog": { 528 case "open-dialog": {
530 let dialog = findParentData(element, "dialog", false); 529 let dialog = findParentData(element, "dialog", false);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + 742 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" +
744 this.value.toLowerCase() + "\"]) { display: none; }"; 743 this.value.toLowerCase() + "\"]) { display: none; }";
745 } 744 }
746 } 745 }
747 746
748 // Initialize navigation sidebar 747 // Initialize navigation sidebar
749 ext.backgroundPage.sendMessage({ 748 ext.backgroundPage.sendMessage({
750 type: "app.get", 749 type: "app.get",
751 what: "addonVersion" 750 what: "addonVersion"
752 }, 751 },
753 addonVersion => 752 (addonVersion) =>
754 { 753 {
755 E("abp-version").textContent = addonVersion; 754 E("abp-version").textContent = addonVersion;
756 }); 755 });
757 getDocLink("releases", link => 756 getDocLink("releases", (link) =>
758 { 757 {
759 E("link-version").setAttribute("href", link); 758 E("link-version").setAttribute("href", link);
760 }); 759 });
761 760
762 updateShareLink(); 761 updateShareLink();
763 updateTooltips(); 762 updateTooltips();
764 763
765 // Initialize interactive UI elements 764 // Initialize interactive UI elements
766 document.body.addEventListener("click", onClick, false); 765 document.body.addEventListener("click", onClick, false);
767 document.body.addEventListener("keyup", onKeyUp, false); 766 document.body.addEventListener("keyup", onKeyUp, false);
768 let placeholderValue = getMessage("options_dialog_language_find"); 767 let placeholderValue = getMessage("options_dialog_language_find");
769 E("find-language").setAttribute("placeholder", placeholderValue); 768 E("find-language").setAttribute("placeholder", placeholderValue);
770 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 769 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
771 E("whitelisting-textbox").addEventListener("keypress", e => 770 E("whitelisting-textbox").addEventListener("keypress", (e) =>
772 { 771 {
773 if (getKey(e) == "Enter") 772 if (getKey(e) == "Enter")
774 addWhitelistedDomain(); 773 addWhitelistedDomain();
775 }, false); 774 }, false);
776 775
777 // Advanced tab 776 // Advanced tab
778 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); 777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]");
779 tweaks = Array.prototype.map.call(tweaks, checkbox => 778 tweaks = Array.prototype.map.call(tweaks, (checkbox) =>
780 { 779 {
781 return checkbox.getAttribute("data-pref"); 780 return checkbox.getAttribute("data-pref");
782 }); 781 });
783 for (let key of tweaks) 782 for (let key of tweaks)
784 { 783 {
785 getPref(key, value => 784 getPref(key, (value) =>
786 { 785 {
787 onPrefMessage(key, value, true); 786 onPrefMessage(key, value, true);
788 }); 787 });
789 } 788 }
790 ext.backgroundPage.sendMessage({ 789 ext.backgroundPage.sendMessage({
791 type: "app.get", 790 type: "app.get",
792 what: "features" 791 what: "features"
793 }, 792 },
794 features => 793 (features) =>
795 { 794 {
796 hidePref("show_devtools_panel", !features.devToolsPanel); 795 hidePref("show_devtools_panel", !features.devToolsPanel);
797 }); 796 });
798 797
799 let filterTextbox = document.querySelector("#custom-filters-add input"); 798 let filterTextbox = document.querySelector("#custom-filters-add input");
800 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 799 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
801 filterTextbox.setAttribute("placeholder", placeholderValue); 800 filterTextbox.setAttribute("placeholder", placeholderValue);
802 function addCustomFilters() 801 function addCustomFilters()
803 { 802 {
804 let filterText = filterTextbox.value; 803 let filterText = filterTextbox.value;
805 sendMessageHandleErrors({ 804 sendMessageHandleErrors({
806 type: "filters.add", 805 type: "filters.add",
807 text: filterText 806 text: filterText
808 }, 807 },
809 () => 808 () =>
810 { 809 {
811 filterTextbox.value = ""; 810 filterTextbox.value = "";
812 }); 811 });
813 } 812 }
814 E("custom-filters-add").addEventListener("submit", e => 813 E("custom-filters-add").addEventListener("submit", (e) =>
815 { 814 {
816 e.preventDefault(); 815 e.preventDefault();
817 addCustomFilters(); 816 addCustomFilters();
818 }, false); 817 }, false);
818
819 // Help tab
820 getDocLink("faq", (link) =>
821 {
822 E("link-faq").setAttribute("href", link);
823 });
824 getDocLink("social_twitter", (link) =>
825 {
826 E("link-twitter").setAttribute("href", link);
827 });
828 getDocLink("social_facebook", (link) =>
829 {
830 E("link-facebook").setAttribute("href", link);
831 });
832 getDocLink("social_gplus", (link) =>
833 {
834 E("link-gplus").setAttribute("href", link);
835 });
836 getDocLink("social_renren", (link) =>
837 {
838 E("link-renren").setAttribute("href", link);
839 });
840 getDocLink("social_weibo", (link) =>
841 {
842 E("link-weibo").setAttribute("href", link);
843 });
844
845 // Set forum link
846 ext.backgroundPage.sendMessage({
847 type: "app.get",
848 what: "platform"
849 },
850 (platform) =>
851 {
852 ext.backgroundPage.sendMessage({
853 type: "app.get",
854 what: "application"
855 },
856 (application) =>
857 {
858 if (platform == "chromium" && application != "opera")
859 application = "chrome";
860
861 getDocLink(application + "_support", (link) =>
862 {
863 E("link-forum").setAttribute("href", link);
864 });
865 });
866 });
819 867
820 E("dialog").addEventListener("keydown", function(e) 868 E("dialog").addEventListener("keydown", function(e)
821 { 869 {
822 switch (getKey(e)) 870 switch (getKey(e))
823 { 871 {
824 case "Escape": 872 case "Escape":
825 closeDialog(); 873 closeDialog();
826 break; 874 break;
827 case "Tab": 875 case "Tab":
828 if (e.shiftKey) 876 if (e.shiftKey)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 filtersMap = Object.create(null); 925 filtersMap = Object.create(null);
878 926
879 // Empty collections and lists 927 // Empty collections and lists
880 for (let property in collections) 928 for (let property in collections)
881 collections[property].clearAll(); 929 collections[property].clearAll();
882 930
883 ext.backgroundPage.sendMessage({ 931 ext.backgroundPage.sendMessage({
884 type: "subscriptions.get", 932 type: "subscriptions.get",
885 special: true 933 special: true
886 }, 934 },
887 subscriptions => 935 (subscriptions) =>
888 { 936 {
889 // Load filters 937 // Load filters
890 for (let subscription of subscriptions) 938 for (let subscription of subscriptions)
891 { 939 {
892 ext.backgroundPage.sendMessage({ 940 ext.backgroundPage.sendMessage({
893 type: "filters.get", 941 type: "filters.get",
894 subscriptionUrl: subscription.url 942 subscriptionUrl: subscription.url
895 }, 943 },
896 filters => 944 (filters) =>
897 { 945 {
898 for (let filter of filters) 946 for (let filter of filters)
899 updateFilter(filter); 947 updateFilter(filter);
900 }); 948 });
901 } 949 }
902 }); 950 });
903 loadRecommendations(); 951 loadRecommendations();
904 ext.backgroundPage.sendMessage({ 952 ext.backgroundPage.sendMessage({
905 type: "prefs.get", 953 type: "prefs.get",
906 key: "subscriptions_exceptionsurl" 954 key: "subscriptions_exceptionsurl"
907 }, 955 },
908 url => 956 (url) =>
909 { 957 {
910 acceptableAdsUrl = url; 958 acceptableAdsUrl = url;
911 addSubscription({ 959 addSubscription({
912 url: acceptableAdsUrl, 960 url: acceptableAdsUrl,
913 disabled: true 961 disabled: true
914 }); 962 });
915 963
916 // Load user subscriptions 964 // Load user subscriptions
917 ext.backgroundPage.sendMessage({ 965 ext.backgroundPage.sendMessage({
918 type: "subscriptions.get", 966 type: "subscriptions.get",
919 downloadable: true 967 downloadable: true
920 }, 968 },
921 subscriptions => 969 (subscriptions) =>
922 { 970 {
923 for (let subscription of subscriptions) 971 for (let subscription of subscriptions)
924 onSubscriptionMessage("added", subscription); 972 onSubscriptionMessage("added", subscription);
925 }); 973 });
926 }); 974 });
927 } 975 }
928 976
929 function addWhitelistedDomain() 977 function addWhitelistedDomain()
930 { 978 {
931 let domain = E("whitelisting-textbox"); 979 let domain = E("whitelisting-textbox");
932 if (domain.value) 980 if (domain.value)
933 { 981 {
934 sendMessageHandleErrors({ 982 sendMessageHandleErrors({
935 type: "filters.add", 983 type: "filters.add",
936 text: "@@||" + domain.value.toLowerCase() + "^$document" 984 text: "@@||" + domain.value.toLowerCase() + "^$document"
937 }); 985 });
938 } 986 }
939 987
940 domain.value = ""; 988 domain.value = "";
941 document.querySelector("#whitelisting .controls"). 989 document.querySelector("#whitelisting .controls")
942 classList.remove("mode-edit"); 990 .classList.remove("mode-edit");
943 } 991 }
944 992
945 function editCustomFilters() 993 function editCustomFilters()
946 { 994 {
947 let filterTexts = []; 995 let filterTexts = [];
948 for (let customFilterItem of collections.customFilters.items) 996 for (let customFilterItem of collections.customFilters.items)
949 filterTexts.push(customFilterItem.text); 997 filterTexts.push(customFilterItem.text);
950 E("custom-filters-raw").value = filterTexts.join("\n"); 998 E("custom-filters-raw").value = filterTexts.join("\n");
951 } 999 }
952 1000
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 function hidePref(key, value) 1095 function hidePref(key, value)
1048 { 1096 {
1049 let element = document.querySelector("[data-pref='" + key + "']"); 1097 let element = document.querySelector("[data-pref='" + key + "']");
1050 if (element) 1098 if (element)
1051 element.setAttribute("aria-hidden", value); 1099 element.setAttribute("aria-hidden", value);
1052 } 1100 }
1053 1101
1054 function getPref(key, callback) 1102 function getPref(key, callback)
1055 { 1103 {
1056 let checkPref = getPref.checks[key] || getPref.checkNone; 1104 let checkPref = getPref.checks[key] || getPref.checkNone;
1057 checkPref(isActive => 1105 checkPref((isActive) =>
1058 { 1106 {
1059 if (!isActive) 1107 if (!isActive)
1060 { 1108 {
1061 hidePref(key, !isActive); 1109 hidePref(key, !isActive);
1062 return; 1110 return;
1063 } 1111 }
1064 1112
1065 ext.backgroundPage.sendMessage({ 1113 ext.backgroundPage.sendMessage({
1066 type: "prefs.get", 1114 type: "prefs.get",
1067 key 1115 key
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 } 1170 }
1123 } 1171 }
1124 1172
1125 for (let sharedResource of shareResources) 1173 for (let sharedResource of shareResources)
1126 checkShareResource(sharedResource, onResult); 1174 checkShareResource(sharedResource, onResult);
1127 } 1175 }
1128 1176
1129 function getMessages(id) 1177 function getMessages(id)
1130 { 1178 {
1131 let messages = []; 1179 let messages = [];
1132 for (let i = 1, message = ext.i18n.getMessage(id + "_" + i); message; i++) 1180 for (let i = 1; true; i++)
1181 {
1182 let message = ext.i18n.getMessage(id + "_" + i);
1183 if (!message)
1184 break;
1185
1133 messages.push(message); 1186 messages.push(message);
1187 }
1134 return messages; 1188 return messages;
1135 } 1189 }
1136 1190
1137 function updateTooltips() 1191 function updateTooltips()
1138 { 1192 {
1139 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); 1193 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
1140 for (let anchor of anchors) 1194 for (let anchor of anchors)
1141 { 1195 {
1142 let id = anchor.getAttribute("data-tooltip"); 1196 let id = anchor.getAttribute("data-tooltip");
1143 1197
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 paragraph.innerHTML = bottomText; 1244 paragraph.innerHTML = bottomText;
1191 notes.appendChild(paragraph); 1245 notes.appendChild(paragraph);
1192 } 1246 }
1193 tooltip.appendChild(notes); 1247 tooltip.appendChild(notes);
1194 } 1248 }
1195 1249
1196 wrapper.appendChild(tooltip); 1250 wrapper.appendChild(tooltip);
1197 } 1251 }
1198 } 1252 }
1199 1253
1200 ext.onMessage.addListener(message => 1254 ext.onMessage.addListener((message) =>
1201 { 1255 {
1202 switch (message.type) 1256 switch (message.type)
1203 { 1257 {
1204 case "app.respond": 1258 case "app.respond":
1205 switch (message.action) 1259 switch (message.action)
1206 { 1260 {
1207 case "addSubscription": 1261 case "addSubscription":
1208 let subscription = message.args[0]; 1262 let subscription = message.args[0];
1209 let dialog = E("dialog-content-predefined"); 1263 let dialog = E("dialog-content-predefined");
1210 dialog.querySelector("h3").textContent = subscription.title || ""; 1264 dialog.querySelector("h3").textContent = subscription.title || "";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 }); 1297 });
1244 ext.backgroundPage.sendMessage({ 1298 ext.backgroundPage.sendMessage({
1245 type: "subscriptions.listen", 1299 type: "subscriptions.listen",
1246 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1300 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1247 "title", "downloadStatus", "downloading"] 1301 "title", "downloadStatus", "downloading"]
1248 }); 1302 });
1249 1303
1250 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1304 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1251 window.addEventListener("hashchange", onHashChange, false); 1305 window.addEventListener("hashchange", onHashChange, false);
1252 } 1306 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld