Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 while (element) | 510 while (element) |
511 { | 511 { |
512 if (element.hasAttribute("data-" + dataName)) | 512 if (element.hasAttribute("data-" + dataName)) |
513 return returnElement ? element : element.getAttribute("data-" + dataName ); | 513 return returnElement ? element : element.getAttribute("data-" + dataName ); |
514 | 514 |
515 element = element.parentElement; | 515 element = element.parentElement; |
516 } | 516 } |
517 return null; | 517 return null; |
518 } | 518 } |
519 | 519 |
520 function sendMessageHandleErrors(message, onSuccess) | |
521 { | |
522 ext.backgroundPage.sendMessage(message, function(errors) | |
523 { | |
524 if (errors.length > 0) | |
525 alert(errors.join("\n")); | |
526 else if (onSuccess) | |
527 onSuccess(); | |
528 }); | |
529 } | |
530 | |
520 function onClick(e) | 531 function onClick(e) |
521 { | 532 { |
522 var context = document.querySelector(".show-context-menu"); | 533 var context = document.querySelector(".show-context-menu"); |
523 if (context) | 534 if (context) |
524 context.classList.remove("show-context-menu"); | 535 context.classList.remove("show-context-menu"); |
525 | 536 |
526 var element = e.target; | 537 var element = e.target; |
527 while (true) | 538 while (true) |
528 { | 539 { |
529 if (!element) | 540 if (!element) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 break; | 581 break; |
571 case "import-subscription": | 582 case "import-subscription": |
572 var url = E("blockingList-textbox").value; | 583 var url = E("blockingList-textbox").value; |
573 addEnableSubscription(url); | 584 addEnableSubscription(url); |
574 closeDialog(); | 585 closeDialog(); |
575 break; | 586 break; |
576 case "open-dialog": | 587 case "open-dialog": |
577 openDialog(element.getAttribute("data-dialog")); | 588 openDialog(element.getAttribute("data-dialog")); |
578 break; | 589 break; |
579 case "save-custom-filters": | 590 case "save-custom-filters": |
580 ext.backgroundPage.sendMessage( | 591 sendMessageHandleErrors( |
581 { | 592 { |
582 type: "filters.importRaw", | 593 type: "filters.importRaw", |
583 text: E("custom-filters-raw").value | 594 text: E("custom-filters-raw").value |
595 }, | |
596 function() | |
597 { | |
598 E("custom-filters").classList.remove("mode-edit"); | |
584 }); | 599 }); |
585 E("custom-filters").classList.remove("mode-edit"); | |
586 break; | 600 break; |
587 case "switch-tab": | 601 case "switch-tab": |
588 document.body.setAttribute("data-tab", | 602 document.body.setAttribute("data-tab", |
589 element.getAttribute("data-tab")); | 603 element.getAttribute("data-tab")); |
590 break; | 604 break; |
591 case "toggle-pref": | 605 case "toggle-pref": |
592 ext.backgroundPage.sendMessage( | 606 ext.backgroundPage.sendMessage( |
593 { | 607 { |
594 type: "prefs.toggle", | 608 type: "prefs.toggle", |
595 key: element.getAttribute("data-pref") | 609 key: findParentData(element, "pref", false) |
596 }); | 610 }); |
597 break; | 611 break; |
598 case "update-all-subscriptions": | 612 case "update-all-subscriptions": |
599 ext.backgroundPage.sendMessage( | 613 ext.backgroundPage.sendMessage( |
600 { | 614 { |
601 type: "subscriptions.update" | 615 type: "subscriptions.update" |
602 }); | 616 }); |
603 break; | 617 break; |
604 case "open-context-menu": | 618 case "open-context-menu": |
605 var listItem = findParentData(element, "access", true); | 619 var listItem = findParentData(element, "access", true); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 var placeholderValue = getMessage("options_dialog_language_find"); | 690 var placeholderValue = getMessage("options_dialog_language_find"); |
677 E("find-language").setAttribute("placeholder", placeholderValue); | 691 E("find-language").setAttribute("placeholder", placeholderValue); |
678 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 692 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
679 E("whitelisting-textbox").addEventListener("keypress", function(e) | 693 E("whitelisting-textbox").addEventListener("keypress", function(e) |
680 { | 694 { |
681 if (getKey(e) == "Enter") | 695 if (getKey(e) == "Enter") |
682 addWhitelistedDomain(); | 696 addWhitelistedDomain(); |
683 }, false); | 697 }, false); |
684 | 698 |
685 // Advanced tab | 699 // Advanced tab |
686 var tweaks = document.querySelectorAll("#tweaks button[role='checkbox'][data -pref]"); | 700 var tweaks = document.querySelectorAll("#tweaks li[data-pref]"); |
687 tweaks = Array.prototype.map.call(tweaks, function(checkbox) | 701 tweaks = Array.prototype.map.call(tweaks, function(checkbox) |
688 { | 702 { |
689 return checkbox.getAttribute("data-pref"); | 703 return checkbox.getAttribute("data-pref"); |
690 }); | 704 }); |
691 tweaks.forEach(function(name) | 705 tweaks.forEach(function(key) |
692 { | 706 { |
693 getPref(name, function(value) | 707 getPref(key, function(value) |
694 { | 708 { |
695 onPrefMessage(name, value); | 709 onPrefMessage(key, value); |
696 }); | 710 }); |
711 }); | |
712 ext.backgroundPage.sendMessage( | |
713 { | |
714 type: "app.get", | |
715 what: "features" | |
716 }, | |
717 function(features) | |
718 { | |
719 hidePref("show_devtools_panel", !features.devToolsPanel); | |
720 hidePref("safari_contentblocker", !features.safariContentBlocker); | |
697 }); | 721 }); |
698 | 722 |
699 var filterTextbox = document.querySelector("#custom-filters-add input"); | 723 var filterTextbox = document.querySelector("#custom-filters-add input"); |
700 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); | 724 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); |
701 filterTextbox.setAttribute("placeholder", placeholderValue); | 725 filterTextbox.setAttribute("placeholder", placeholderValue); |
702 function addCustomFilters() | 726 function addCustomFilters() |
703 { | 727 { |
704 var filterText = filterTextbox.value; | 728 var filterText = filterTextbox.value; |
705 ext.backgroundPage.sendMessage( | 729 sendMessageHandleErrors( |
706 { | 730 { |
707 type: "filters.add", | 731 type: "filters.add", |
708 text: filterText | 732 text: filterText |
733 }, | |
734 function() | |
735 { | |
736 filterTextbox.value = ""; | |
709 }); | 737 }); |
710 filterTextbox.value = ""; | |
711 } | 738 } |
712 E("custom-filters-add").addEventListener("submit", function(e) | 739 E("custom-filters-add").addEventListener("submit", function(e) |
713 { | 740 { |
714 e.preventDefault(); | 741 e.preventDefault(); |
715 addCustomFilters(); | 742 addCustomFilters(); |
716 }, false); | 743 }, false); |
717 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); | 744 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); |
718 | 745 |
719 E("dialog").addEventListener("keydown", function(e) | 746 E("dialog").addEventListener("keydown", function(e) |
720 { | 747 { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 onSubscriptionMessage("added", subscriptions[i]); | 847 onSubscriptionMessage("added", subscriptions[i]); |
821 }); | 848 }); |
822 }); | 849 }); |
823 } | 850 } |
824 | 851 |
825 function addWhitelistedDomain() | 852 function addWhitelistedDomain() |
826 { | 853 { |
827 var domain = E("whitelisting-textbox"); | 854 var domain = E("whitelisting-textbox"); |
828 if (domain.value) | 855 if (domain.value) |
829 { | 856 { |
830 ext.backgroundPage.sendMessage( | 857 sendMessageHandleErrors( |
831 { | 858 { |
832 type: "filters.add", | 859 type: "filters.add", |
833 text: "@@||" + domain.value.toLowerCase() + "^$document" | 860 text: "@@||" + domain.value.toLowerCase() + "^$document" |
834 }); | 861 }); |
835 } | 862 } |
836 | 863 |
837 domain.value = ""; | 864 domain.value = ""; |
838 document.querySelector("#whitelisting .controls").classList.remove("mode-edi t"); | 865 document.querySelector("#whitelisting .controls").classList.remove("mode-edi t"); |
839 } | 866 } |
840 | 867 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
950 break; | 977 break; |
951 case "title": | 978 case "title": |
952 // TODO: NYI | 979 // TODO: NYI |
953 break; | 980 break; |
954 } | 981 } |
955 } | 982 } |
956 | 983 |
957 function hidePref(key, value) | 984 function hidePref(key, value) |
958 { | 985 { |
959 var element = document.querySelector("[data-pref='" + key + "']"); | 986 var element = document.querySelector("[data-pref='" + key + "']"); |
960 if (!element) | 987 if (element) |
961 return; | 988 element.setAttribute("aria-hidden", value); |
962 | |
963 var parent = findParentData(element, "optional", true); | |
964 parent.setAttribute("aria-hidden", value); | |
965 } | 989 } |
966 | 990 |
967 function getPref(key, callback) | 991 function getPref(key, callback) |
968 { | 992 { |
969 var checkPref = getPref.checks[key] || getPref.checkNone; | 993 var checkPref = getPref.checks[key] || getPref.checkNone; |
970 checkPref(function(isActive) | 994 checkPref(function(isActive) |
971 { | 995 { |
972 if (!isActive) | 996 if (!isActive) |
973 { | 997 { |
974 hidePref(key, !isActive); | 998 hidePref(key, !isActive); |
975 return; | 999 return; |
976 } | 1000 } |
977 | 1001 |
978 ext.backgroundPage.sendMessage( | 1002 ext.backgroundPage.sendMessage( |
979 { | 1003 { |
980 type: "prefs.get", | 1004 type: "prefs.get", |
981 key: key | 1005 key: key |
982 }, callback); | 1006 }, callback); |
983 }); | 1007 }); |
984 } | 1008 } |
1009 | |
985 getPref.checkNone = function(callback) | 1010 getPref.checkNone = function(callback) |
saroyanm
2016/03/11 14:55:58
Detail: I assume you grouped the functions for rea
Thomas Greiner
2016/03/15 15:39:26
Done.
| |
986 { | 1011 { |
987 callback(true); | 1012 callback(true); |
988 }; | 1013 }; |
1014 | |
989 getPref.checks = | 1015 getPref.checks = |
990 { | 1016 { |
991 notifications_ignoredcategories: function(callback) | 1017 notifications_ignoredcategories: function(callback) |
992 { | 1018 { |
993 getPref("notifications_showui", callback); | 1019 getPref("notifications_showui", callback); |
994 }, | |
995 safari_contentblocker: function(callback) | |
996 { | |
997 ext.backgroundPage.sendMessage( | |
998 { | |
999 type: "app.get", | |
1000 what: "features" | |
1001 }, | |
1002 function(features) | |
1003 { | |
1004 callback(features.safariContentBlocker); | |
1005 }); | |
1006 } | 1020 } |
1007 }; | 1021 }; |
1008 | 1022 |
1009 function onPrefMessage(key, value) | 1023 function onPrefMessage(key, value) |
1010 { | 1024 { |
1011 var checkbox = document.querySelector("[data-pref='" + key + "']"); | 1025 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']"); |
1012 if (checkbox) | 1026 if (checkbox) |
1013 { | 1027 { |
1014 if (key == "notifications_ignoredcategories") | 1028 if (key == "notifications_ignoredcategories") |
1015 value = (value.indexOf("*") == -1); | 1029 value = (value.indexOf("*") == -1); |
1016 checkbox.setAttribute("aria-checked", value); | 1030 checkbox.setAttribute("aria-checked", value); |
1017 } | 1031 } |
1018 else if (key == "notifications_showui") | 1032 else if (key == "notifications_showui") |
1019 hidePref("notifications_ignoredcategories", !value); | 1033 hidePref("notifications_ignoredcategories", !value); |
1020 } | 1034 } |
1021 | 1035 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1066 { | 1080 { |
1067 case "app.listen": | 1081 case "app.listen": |
1068 if (message.action == "addSubscription") | 1082 if (message.action == "addSubscription") |
1069 { | 1083 { |
1070 var subscription = message.args[0]; | 1084 var subscription = message.args[0]; |
1071 var dialog = E("dialog-content-predefined"); | 1085 var dialog = E("dialog-content-predefined"); |
1072 dialog.querySelector("h3").textContent = subscription.title || ""; | 1086 dialog.querySelector("h3").textContent = subscription.title || ""; |
1073 dialog.querySelector(".url").textContent = subscription.url; | 1087 dialog.querySelector(".url").textContent = subscription.url; |
1074 openDialog("predefined"); | 1088 openDialog("predefined"); |
1075 } | 1089 } |
1076 else if (message.action == "error") | |
1077 { | |
1078 alert(message.args.join("\n")); | |
1079 } | |
1080 break; | 1090 break; |
1081 case "filters.listen": | 1091 case "filters.listen": |
1082 onFilterMessage(message.action, message.args[0]); | 1092 onFilterMessage(message.action, message.args[0]); |
1083 break; | 1093 break; |
1084 case "prefs.listen": | 1094 case "prefs.listen": |
1085 onPrefMessage(message.action, message.args[0]); | 1095 onPrefMessage(message.action, message.args[0]); |
1086 break; | 1096 break; |
1087 case "subscriptions.listen": | 1097 case "subscriptions.listen": |
1088 onSubscriptionMessage(message.action, message.args[0]); | 1098 onSubscriptionMessage(message.action, message.args[0]); |
1089 break; | 1099 break; |
1090 } | 1100 } |
1091 }); | 1101 }); |
1092 | 1102 |
1093 ext.backgroundPage.sendMessage( | 1103 ext.backgroundPage.sendMessage( |
1094 { | 1104 { |
1095 type: "app.listen", | 1105 type: "app.listen", |
1096 filter: ["addSubscription", "error"] | 1106 filter: ["addSubscription", "error"] |
1097 }); | 1107 }); |
1098 ext.backgroundPage.sendMessage( | 1108 ext.backgroundPage.sendMessage( |
1099 { | 1109 { |
1100 type: "filters.listen", | 1110 type: "filters.listen", |
1101 filter: ["added", "loaded", "removed"] | 1111 filter: ["added", "loaded", "removed"] |
1102 }); | 1112 }); |
1103 ext.backgroundPage.sendMessage( | 1113 ext.backgroundPage.sendMessage( |
1104 { | 1114 { |
1105 type: "prefs.listen", | 1115 type: "prefs.listen", |
1106 filter: ["notifications_ignoredcategories", "notifications_showui", | 1116 filter: ["notifications_ignoredcategories", "notifications_showui", |
1107 "safari_contentblocker", "shouldShowBlockElementMenu"] | 1117 "safari_contentblocker", "show_devtools_panel", |
1118 "shouldShowBlockElementMenu"] | |
1108 }); | 1119 }); |
1109 ext.backgroundPage.sendMessage( | 1120 ext.backgroundPage.sendMessage( |
1110 { | 1121 { |
1111 type: "subscriptions.listen", | 1122 type: "subscriptions.listen", |
1112 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] | 1123 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1124 "title"] | |
1113 }); | 1125 }); |
1114 | 1126 |
1115 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1127 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1116 })(); | 1128 })(); |
LEFT | RIGHT |