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: 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 | « 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
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 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup, 18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup,
19 E */ 19 E */
20 20
21 "use strict"; 21 "use strict";
22 22
23 { 23 {
24 let subscriptionsMap = Object.create(null); 24 let subscriptionsMap = Object.create(null);
25 let filtersMap = Object.create(null); 25 let filtersMap = Object.create(null);
26 let collections = Object.create(null); 26 let collections = Object.create(null);
27 let acceptableAdsUrl = null; 27 let acceptableAdsUrl = null;
28 let {getMessage} = ext.i18n; 28 let {getMessage} = ext.i18n;
29 let filterErrors = new Map([ 29 let filterErrors = new Map([
Thomas Greiner 2017/03/01 17:39:35 Why do you use `Map` here but not in messageRespon
kzar 2017/03/07 12:48:32 Well I changed this one since it helped fix some l
30 ["synchronize_invalid_url", 30 ["synchronize_invalid_url",
31 "options_filterList_lastDownload_invalidURL"], 31 "options_filterList_lastDownload_invalidURL"],
32 ["synchronize_connection_error", 32 ["synchronize_connection_error",
33 "options_filterList_lastDownload_connectionError"], 33 "options_filterList_lastDownload_connectionError"],
34 ["synchronize_invalid_data", 34 ["synchronize_invalid_data",
35 "options_filterList_lastDownload_invalidData"], 35 "options_filterList_lastDownload_invalidData"],
36 ["synchronize_checksum_mismatch", 36 ["synchronize_checksum_mismatch",
37 "options_filterList_lastDownload_checksumMismatch"] 37 "options_filterList_lastDownload_checksumMismatch"]
38 ]); 38 ]);
39 39
(...skipping 345 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 {
(...skipping 24 matching lines...) Expand all
497 let url = dialog.querySelector(".url").textContent; 497 let url = dialog.querySelector(".url").textContent;
498 addEnableSubscription(url, title); 498 addEnableSubscription(url, title);
499 closeDialog(); 499 closeDialog();
500 break; 500 break;
501 } 501 }
502 case "cancel-custom-filters": 502 case "cancel-custom-filters":
503 E("custom-filters").classList.remove("mode-edit"); 503 E("custom-filters").classList.remove("mode-edit");
504 break; 504 break;
505 case "cancel-domain-exception": 505 case "cancel-domain-exception":
506 E("whitelisting-textbox").value = ""; 506 E("whitelisting-textbox").value = "";
507 document.querySelector("#whitelisting .controls").classList. 507 document.querySelector("#whitelisting .controls").classList
508 remove("mode-edit"); 508 .remove("mode-edit");
509 break; 509 break;
510 case "close-dialog": 510 case "close-dialog":
511 closeDialog(); 511 closeDialog();
512 break; 512 break;
513 case "edit-custom-filters": 513 case "edit-custom-filters":
514 E("custom-filters").classList.add("mode-edit"); 514 E("custom-filters").classList.add("mode-edit");
515 editCustomFilters(); 515 editCustomFilters();
516 break; 516 break;
517 case "edit-domain-exception": 517 case "edit-domain-exception":
518 document.querySelector("#whitelisting .controls").classList. 518 document.querySelector("#whitelisting .controls").classList
519 add("mode-edit"); 519 .add("mode-edit");
520 E("whitelisting-textbox").focus(); 520 E("whitelisting-textbox").focus();
521 break; 521 break;
522 case "import-subscription": { 522 case "import-subscription": {
523 let url = E("blockingList-textbox").value; 523 let url = E("blockingList-textbox").value;
524 addEnableSubscription(url); 524 addEnableSubscription(url);
525 closeDialog(); 525 closeDialog();
526 break; 526 break;
527 } 527 }
528 case "open-dialog": { 528 case "open-dialog": {
529 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
742 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + 742 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" +
743 this.value.toLowerCase() + "\"]) { display: none; }"; 743 this.value.toLowerCase() + "\"]) { display: none; }";
744 } 744 }
745 } 745 }
746 746
747 // Initialize navigation sidebar 747 // Initialize navigation sidebar
748 ext.backgroundPage.sendMessage({ 748 ext.backgroundPage.sendMessage({
749 type: "app.get", 749 type: "app.get",
750 what: "addonVersion" 750 what: "addonVersion"
751 }, 751 },
752 addonVersion => 752 (addonVersion) =>
Thomas Greiner 2017/03/01 17:39:35 This being on the same level as the function calls
kzar 2017/03/02 04:36:01 Yes, I think this is how we're expecting the inden
Thomas Greiner 2017/03/07 13:33:01 Nah, because the issue is that putting it in the s
kzar 2017/03/08 10:29:32 Acknowledged.
753 { 753 {
754 E("abp-version").textContent = addonVersion; 754 E("abp-version").textContent = addonVersion;
755 }); 755 });
756 getDocLink("releases", link => 756 getDocLink("releases", (link) =>
757 { 757 {
758 E("link-version").setAttribute("href", link); 758 E("link-version").setAttribute("href", link);
759 }); 759 });
760 760
761 updateShareLink(); 761 updateShareLink();
762 updateTooltips(); 762 updateTooltips();
763 763
764 // Initialize interactive UI elements 764 // Initialize interactive UI elements
765 document.body.addEventListener("click", onClick, false); 765 document.body.addEventListener("click", onClick, false);
766 document.body.addEventListener("keyup", onKeyUp, false); 766 document.body.addEventListener("keyup", onKeyUp, false);
767 let placeholderValue = getMessage("options_dialog_language_find"); 767 let placeholderValue = getMessage("options_dialog_language_find");
768 E("find-language").setAttribute("placeholder", placeholderValue); 768 E("find-language").setAttribute("placeholder", placeholderValue);
769 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 769 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
770 E("whitelisting-textbox").addEventListener("keypress", e => 770 E("whitelisting-textbox").addEventListener("keypress", (e) =>
771 { 771 {
772 if (getKey(e) == "Enter") 772 if (getKey(e) == "Enter")
773 addWhitelistedDomain(); 773 addWhitelistedDomain();
774 }, false); 774 }, false);
775 775
776 // Advanced tab 776 // Advanced tab
777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); 777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]");
778 tweaks = Array.prototype.map.call(tweaks, checkbox => 778 tweaks = Array.prototype.map.call(tweaks, (checkbox) =>
779 { 779 {
780 return checkbox.getAttribute("data-pref"); 780 return checkbox.getAttribute("data-pref");
781 }); 781 });
782 for (let key of tweaks) 782 for (let key of tweaks)
783 { 783 {
784 getPref(key, value => 784 getPref(key, (value) =>
785 { 785 {
786 onPrefMessage(key, value, true); 786 onPrefMessage(key, value, true);
787 }); 787 });
788 } 788 }
789 ext.backgroundPage.sendMessage({ 789 ext.backgroundPage.sendMessage({
790 type: "app.get", 790 type: "app.get",
791 what: "features" 791 what: "features"
792 }, 792 },
793 features => 793 (features) =>
794 { 794 {
795 hidePref("show_devtools_panel", !features.devToolsPanel); 795 hidePref("show_devtools_panel", !features.devToolsPanel);
796 }); 796 });
797 797
798 let filterTextbox = document.querySelector("#custom-filters-add input"); 798 let filterTextbox = document.querySelector("#custom-filters-add input");
799 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 799 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
800 filterTextbox.setAttribute("placeholder", placeholderValue); 800 filterTextbox.setAttribute("placeholder", placeholderValue);
801 function addCustomFilters() 801 function addCustomFilters()
802 { 802 {
803 let filterText = filterTextbox.value; 803 let filterText = filterTextbox.value;
804 sendMessageHandleErrors({ 804 sendMessageHandleErrors({
805 type: "filters.add", 805 type: "filters.add",
806 text: filterText 806 text: filterText
807 }, 807 },
808 () => 808 () =>
809 { 809 {
810 filterTextbox.value = ""; 810 filterTextbox.value = "";
811 }); 811 });
812 } 812 }
813 E("custom-filters-add").addEventListener("submit", e => 813 E("custom-filters-add").addEventListener("submit", (e) =>
814 { 814 {
815 e.preventDefault(); 815 e.preventDefault();
816 addCustomFilters(); 816 addCustomFilters();
817 }, 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 });
818 867
819 E("dialog").addEventListener("keydown", function(e) 868 E("dialog").addEventListener("keydown", function(e)
820 { 869 {
821 switch (getKey(e)) 870 switch (getKey(e))
822 { 871 {
823 case "Escape": 872 case "Escape":
824 closeDialog(); 873 closeDialog();
825 break; 874 break;
826 case "Tab": 875 case "Tab":
827 if (e.shiftKey) 876 if (e.shiftKey)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 filtersMap = Object.create(null); 925 filtersMap = Object.create(null);
877 926
878 // Empty collections and lists 927 // Empty collections and lists
879 for (let property in collections) 928 for (let property in collections)
880 collections[property].clearAll(); 929 collections[property].clearAll();
881 930
882 ext.backgroundPage.sendMessage({ 931 ext.backgroundPage.sendMessage({
883 type: "subscriptions.get", 932 type: "subscriptions.get",
884 special: true 933 special: true
885 }, 934 },
886 subscriptions => 935 (subscriptions) =>
887 { 936 {
888 // Load filters 937 // Load filters
889 for (let subscription of subscriptions) 938 for (let subscription of subscriptions)
890 { 939 {
891 ext.backgroundPage.sendMessage({ 940 ext.backgroundPage.sendMessage({
892 type: "filters.get", 941 type: "filters.get",
893 subscriptionUrl: subscription.url 942 subscriptionUrl: subscription.url
894 }, 943 },
895 filters => 944 (filters) =>
896 { 945 {
897 for (let filter of filters) 946 for (let filter of filters)
898 updateFilter(filter); 947 updateFilter(filter);
899 }); 948 });
900 } 949 }
901 }); 950 });
902 loadRecommendations(); 951 loadRecommendations();
903 ext.backgroundPage.sendMessage({ 952 ext.backgroundPage.sendMessage({
904 type: "prefs.get", 953 type: "prefs.get",
905 key: "subscriptions_exceptionsurl" 954 key: "subscriptions_exceptionsurl"
906 }, 955 },
907 url => 956 (url) =>
908 { 957 {
909 acceptableAdsUrl = url; 958 acceptableAdsUrl = url;
910 addSubscription({ 959 addSubscription({
911 url: acceptableAdsUrl, 960 url: acceptableAdsUrl,
912 disabled: true 961 disabled: true
913 }); 962 });
914 963
915 // Load user subscriptions 964 // Load user subscriptions
916 ext.backgroundPage.sendMessage({ 965 ext.backgroundPage.sendMessage({
917 type: "subscriptions.get", 966 type: "subscriptions.get",
918 downloadable: true 967 downloadable: true
919 }, 968 },
920 subscriptions => 969 (subscriptions) =>
921 { 970 {
922 for (let subscription of subscriptions) 971 for (let subscription of subscriptions)
923 onSubscriptionMessage("added", subscription); 972 onSubscriptionMessage("added", subscription);
924 }); 973 });
925 }); 974 });
926 } 975 }
927 976
928 function addWhitelistedDomain() 977 function addWhitelistedDomain()
929 { 978 {
930 let domain = E("whitelisting-textbox"); 979 let domain = E("whitelisting-textbox");
931 if (domain.value) 980 if (domain.value)
932 { 981 {
933 sendMessageHandleErrors({ 982 sendMessageHandleErrors({
934 type: "filters.add", 983 type: "filters.add",
935 text: "@@||" + domain.value.toLowerCase() + "^$document" 984 text: "@@||" + domain.value.toLowerCase() + "^$document"
936 }); 985 });
937 } 986 }
938 987
939 domain.value = ""; 988 domain.value = "";
940 document.querySelector("#whitelisting .controls"). 989 document.querySelector("#whitelisting .controls")
941 classList.remove("mode-edit"); 990 .classList.remove("mode-edit");
942 } 991 }
943 992
944 function editCustomFilters() 993 function editCustomFilters()
945 { 994 {
946 let filterTexts = []; 995 let filterTexts = [];
947 for (let customFilterItem of collections.customFilters.items) 996 for (let customFilterItem of collections.customFilters.items)
948 filterTexts.push(customFilterItem.text); 997 filterTexts.push(customFilterItem.text);
949 E("custom-filters-raw").value = filterTexts.join("\n"); 998 E("custom-filters-raw").value = filterTexts.join("\n");
950 } 999 }
951 1000
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 function hidePref(key, value) 1095 function hidePref(key, value)
1047 { 1096 {
1048 let element = document.querySelector("[data-pref='" + key + "']"); 1097 let element = document.querySelector("[data-pref='" + key + "']");
1049 if (element) 1098 if (element)
1050 element.setAttribute("aria-hidden", value); 1099 element.setAttribute("aria-hidden", value);
1051 } 1100 }
1052 1101
1053 function getPref(key, callback) 1102 function getPref(key, callback)
1054 { 1103 {
1055 let checkPref = getPref.checks[key] || getPref.checkNone; 1104 let checkPref = getPref.checks[key] || getPref.checkNone;
1056 checkPref(isActive => 1105 checkPref((isActive) =>
1057 { 1106 {
1058 if (!isActive) 1107 if (!isActive)
1059 { 1108 {
1060 hidePref(key, !isActive); 1109 hidePref(key, !isActive);
1061 return; 1110 return;
1062 } 1111 }
1063 1112
1064 ext.backgroundPage.sendMessage({ 1113 ext.backgroundPage.sendMessage({
1065 type: "prefs.get", 1114 type: "prefs.get",
1066 key 1115 key
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 paragraph.innerHTML = bottomText; 1244 paragraph.innerHTML = bottomText;
1196 notes.appendChild(paragraph); 1245 notes.appendChild(paragraph);
1197 } 1246 }
1198 tooltip.appendChild(notes); 1247 tooltip.appendChild(notes);
1199 } 1248 }
1200 1249
1201 wrapper.appendChild(tooltip); 1250 wrapper.appendChild(tooltip);
1202 } 1251 }
1203 } 1252 }
1204 1253
1205 ext.onMessage.addListener(message => 1254 ext.onMessage.addListener((message) =>
1206 { 1255 {
1207 switch (message.type) 1256 switch (message.type)
1208 { 1257 {
1209 case "app.respond": 1258 case "app.respond":
1210 switch (message.action) 1259 switch (message.action)
1211 { 1260 {
1212 case "addSubscription": 1261 case "addSubscription":
1213 let subscription = message.args[0]; 1262 let subscription = message.args[0];
1214 let dialog = E("dialog-content-predefined"); 1263 let dialog = E("dialog-content-predefined");
1215 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
1248 }); 1297 });
1249 ext.backgroundPage.sendMessage({ 1298 ext.backgroundPage.sendMessage({
1250 type: "subscriptions.listen", 1299 type: "subscriptions.listen",
1251 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1300 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1252 "title", "downloadStatus", "downloading"] 1301 "title", "downloadStatus", "downloading"]
1253 }); 1302 });
1254 1303
1255 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1304 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1256 window.addEventListener("hashchange", onHashChange, false); 1305 window.addEventListener("hashchange", onHashChange, false);
1257 } 1306 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld