OLD | NEW |
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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 { | 581 { |
582 type: "filters.importRaw", | 582 type: "filters.importRaw", |
583 text: E("custom-filters-raw").value | 583 text: E("custom-filters-raw").value |
584 }); | 584 }); |
585 E("custom-filters").classList.remove("mode-edit"); | 585 E("custom-filters").classList.remove("mode-edit"); |
586 break; | 586 break; |
587 case "switch-tab": | 587 case "switch-tab": |
588 document.body.setAttribute("data-tab", | 588 document.body.setAttribute("data-tab", |
589 element.getAttribute("data-tab")); | 589 element.getAttribute("data-tab")); |
590 break; | 590 break; |
| 591 case "toggle-pref": |
| 592 ext.backgroundPage.sendMessage( |
| 593 { |
| 594 type: "prefs.toggle", |
| 595 key: findParentData(element, "pref", false) |
| 596 }); |
| 597 break; |
591 case "update-all-subscriptions": | 598 case "update-all-subscriptions": |
592 ext.backgroundPage.sendMessage( | 599 ext.backgroundPage.sendMessage( |
593 { | 600 { |
594 type: "subscriptions.update" | 601 type: "subscriptions.update" |
595 }); | 602 }); |
596 break; | 603 break; |
597 case "open-context-menu": | 604 case "open-context-menu": |
598 var listItem = findParentData(element, "access", true); | 605 var listItem = findParentData(element, "access", true); |
599 if (listItem != context) | 606 if (listItem != context) |
600 listItem.classList.add("show-context-menu"); | 607 listItem.classList.add("show-context-menu"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 var placeholderValue = getMessage("options_dialog_language_find"); | 676 var placeholderValue = getMessage("options_dialog_language_find"); |
670 E("find-language").setAttribute("placeholder", placeholderValue); | 677 E("find-language").setAttribute("placeholder", placeholderValue); |
671 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 678 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
672 E("whitelisting-textbox").addEventListener("keypress", function(e) | 679 E("whitelisting-textbox").addEventListener("keypress", function(e) |
673 { | 680 { |
674 if (getKey(e) == "Enter") | 681 if (getKey(e) == "Enter") |
675 addWhitelistedDomain(); | 682 addWhitelistedDomain(); |
676 }, false); | 683 }, false); |
677 | 684 |
678 // Advanced tab | 685 // Advanced tab |
| 686 var tweaks = document.querySelectorAll("#tweaks li[data-pref]"); |
| 687 tweaks = Array.prototype.map.call(tweaks, function(checkbox) |
| 688 { |
| 689 return checkbox.getAttribute("data-pref"); |
| 690 }); |
| 691 tweaks.forEach(function(key) |
| 692 { |
| 693 getPref(key, function(value) |
| 694 { |
| 695 onPrefMessage(key, value); |
| 696 }); |
| 697 }); |
| 698 |
679 var filterTextbox = document.querySelector("#custom-filters-add input"); | 699 var filterTextbox = document.querySelector("#custom-filters-add input"); |
680 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); | 700 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); |
681 filterTextbox.setAttribute("placeholder", placeholderValue); | 701 filterTextbox.setAttribute("placeholder", placeholderValue); |
682 function addCustomFilters() | 702 function addCustomFilters() |
683 { | 703 { |
684 var filterText = filterTextbox.value; | 704 var filterText = filterTextbox.value; |
685 ext.backgroundPage.sendMessage( | 705 ext.backgroundPage.sendMessage( |
686 { | 706 { |
687 type: "filters.add", | 707 type: "filters.add", |
688 text: filterText | 708 text: filterText |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 { | 842 { |
823 var customFilterItems = collections.customFilters.items; | 843 var customFilterItems = collections.customFilters.items; |
824 var filterTexts = []; | 844 var filterTexts = []; |
825 for (var i = 0; i < customFilterItems.length; i++) | 845 for (var i = 0; i < customFilterItems.length; i++) |
826 filterTexts.push(customFilterItems[i].text); | 846 filterTexts.push(customFilterItems[i].text); |
827 E("custom-filters-raw").value = filterTexts.join("\n"); | 847 E("custom-filters-raw").value = filterTexts.join("\n"); |
828 } | 848 } |
829 | 849 |
830 function getAcceptableAdsURL(callback) | 850 function getAcceptableAdsURL(callback) |
831 { | 851 { |
832 ext.backgroundPage.sendMessage( | 852 getPref("subscriptions_exceptionsurl", function(value) |
833 { | |
834 type: "prefs.get", | |
835 key: "subscriptions_exceptionsurl" | |
836 }, | |
837 function(value) | |
838 { | 853 { |
839 getAcceptableAdsURL = function(callback) | 854 getAcceptableAdsURL = function(callback) |
840 { | 855 { |
841 callback(value); | 856 callback(value); |
842 } | 857 }; |
843 getAcceptableAdsURL(callback); | 858 getAcceptableAdsURL(callback); |
844 }); | 859 }); |
845 } | 860 } |
846 | 861 |
847 function addEnableSubscription(url, title, homepage) | 862 function addEnableSubscription(url, title, homepage) |
848 { | 863 { |
849 var messageType = null; | 864 var messageType = null; |
850 var knownSubscription = subscriptionsMap[url]; | 865 var knownSubscription = subscriptionsMap[url]; |
851 if (knownSubscription && knownSubscription.disabled == true) | 866 if (knownSubscription && knownSubscription.disabled == true) |
852 messageType = "subscriptions.toggle" | 867 messageType = "subscriptions.toggle" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 updateShareLink(); | 947 updateShareLink(); |
933 collections.filterLists.removeItem(knownSubscription); | 948 collections.filterLists.removeItem(knownSubscription); |
934 }); | 949 }); |
935 break; | 950 break; |
936 case "title": | 951 case "title": |
937 // TODO: NYI | 952 // TODO: NYI |
938 break; | 953 break; |
939 } | 954 } |
940 } | 955 } |
941 | 956 |
| 957 function hidePref(key, value) |
| 958 { |
| 959 var element = document.querySelector("[data-pref='" + key + "']"); |
| 960 if (element) |
| 961 element.setAttribute("aria-hidden", value); |
| 962 } |
| 963 |
| 964 function getPref(key, callback) |
| 965 { |
| 966 var checkPref = getPref.checks[key] || getPref.checkNone; |
| 967 checkPref(function(isActive) |
| 968 { |
| 969 if (!isActive) |
| 970 { |
| 971 hidePref(key, !isActive); |
| 972 return; |
| 973 } |
| 974 |
| 975 ext.backgroundPage.sendMessage( |
| 976 { |
| 977 type: "prefs.get", |
| 978 key: key |
| 979 }, callback); |
| 980 }); |
| 981 } |
| 982 |
| 983 getPref.checkNone = function(callback) |
| 984 { |
| 985 callback(true); |
| 986 }; |
| 987 |
| 988 getPref.checks = |
| 989 { |
| 990 notifications_ignoredcategories: function(callback) |
| 991 { |
| 992 getPref("notifications_showui", callback); |
| 993 }, |
| 994 safari_contentblocker: function(callback) |
| 995 { |
| 996 ext.backgroundPage.sendMessage( |
| 997 { |
| 998 type: "app.get", |
| 999 what: "features" |
| 1000 }, |
| 1001 function(features) |
| 1002 { |
| 1003 callback(features.safariContentBlocker); |
| 1004 }); |
| 1005 } |
| 1006 }; |
| 1007 |
| 1008 function onPrefMessage(key, value) |
| 1009 { |
| 1010 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role
='checkbox']"); |
| 1011 if (checkbox) |
| 1012 { |
| 1013 if (key == "notifications_ignoredcategories") |
| 1014 value = (value.indexOf("*") == -1); |
| 1015 checkbox.setAttribute("aria-checked", value); |
| 1016 } |
| 1017 else if (key == "notifications_showui") |
| 1018 hidePref("notifications_ignoredcategories", !value); |
| 1019 } |
| 1020 |
942 function onShareLinkClick(e) | 1021 function onShareLinkClick(e) |
943 { | 1022 { |
944 e.preventDefault(); | 1023 e.preventDefault(); |
945 | 1024 |
946 getDocLink("share-general", function(link) | 1025 getDocLink("share-general", function(link) |
947 { | 1026 { |
948 openSharePopup(link); | 1027 openSharePopup(link); |
949 }); | 1028 }); |
950 } | 1029 } |
951 | 1030 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 openDialog("predefined"); | 1073 openDialog("predefined"); |
995 } | 1074 } |
996 else if (message.action == "error") | 1075 else if (message.action == "error") |
997 { | 1076 { |
998 alert(message.args.join("\n")); | 1077 alert(message.args.join("\n")); |
999 } | 1078 } |
1000 break; | 1079 break; |
1001 case "filters.listen": | 1080 case "filters.listen": |
1002 onFilterMessage(message.action, message.args[0]); | 1081 onFilterMessage(message.action, message.args[0]); |
1003 break; | 1082 break; |
| 1083 case "prefs.listen": |
| 1084 onPrefMessage(message.action, message.args[0]); |
| 1085 break; |
1004 case "subscriptions.listen": | 1086 case "subscriptions.listen": |
1005 onSubscriptionMessage(message.action, message.args[0]); | 1087 onSubscriptionMessage(message.action, message.args[0]); |
1006 break; | 1088 break; |
1007 } | 1089 } |
1008 }); | 1090 }); |
1009 | 1091 |
1010 ext.backgroundPage.sendMessage( | 1092 ext.backgroundPage.sendMessage( |
1011 { | 1093 { |
1012 type: "app.listen", | 1094 type: "app.listen", |
1013 filter: ["addSubscription", "error"] | 1095 filter: ["addSubscription", "error"] |
1014 }); | 1096 }); |
1015 ext.backgroundPage.sendMessage( | 1097 ext.backgroundPage.sendMessage( |
1016 { | 1098 { |
1017 type: "filters.listen", | 1099 type: "filters.listen", |
1018 filter: ["added", "loaded", "removed"] | 1100 filter: ["added", "loaded", "removed"] |
1019 }); | 1101 }); |
1020 ext.backgroundPage.sendMessage( | 1102 ext.backgroundPage.sendMessage( |
1021 { | 1103 { |
| 1104 type: "prefs.listen", |
| 1105 filter: ["notifications_ignoredcategories", "notifications_showui", |
| 1106 "safari_contentblocker", "shouldShowBlockElementMenu"] |
| 1107 }); |
| 1108 ext.backgroundPage.sendMessage( |
| 1109 { |
1022 type: "subscriptions.listen", | 1110 type: "subscriptions.listen", |
1023 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title"
] | 1111 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title"
] |
1024 }); | 1112 }); |
1025 | 1113 |
1026 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1114 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1027 })(); | 1115 })(); |
OLD | NEW |