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

Delta Between Two Patch Sets: options.js

Issue 29337729: Issue 2374 - Implemented Tweaks section in options page (Closed)
Left Patch Set: Addressed Manvel's comments Created March 15, 2016, 2:40 p.m.
Right Patch Set: Created March 16, 2016, 11:13 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 | « options.html ('k') | skin/options.css » ('j') | 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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: findParentData(element, "pref", false) 609 key: findParentData(element, "pref", false)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 { 702 {
689 return checkbox.getAttribute("data-pref"); 703 return checkbox.getAttribute("data-pref");
690 }); 704 });
691 tweaks.forEach(function(key) 705 tweaks.forEach(function(key)
692 { 706 {
693 getPref(key, function(value) 707 getPref(key, function(value)
694 { 708 {
695 onPrefMessage(key, value); 709 onPrefMessage(key, value);
696 }); 710 });
697 }); 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);
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
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 getPref.checkNone = function(callback) 1010 getPref.checkNone = function(callback)
984 { 1011 {
985 callback(true); 1012 callback(true);
986 }; 1013 };
987 1014
988 getPref.checks = 1015 getPref.checks =
989 { 1016 {
990 notifications_ignoredcategories: function(callback) 1017 notifications_ignoredcategories: function(callback)
991 { 1018 {
992 getPref("notifications_showui", callback); 1019 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 } 1020 }
1006 }; 1021 };
1007 1022
1008 function onPrefMessage(key, value) 1023 function onPrefMessage(key, value)
1009 { 1024 {
1010 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']"); 1025 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']");
1011 if (checkbox) 1026 if (checkbox)
1012 { 1027 {
1013 if (key == "notifications_ignoredcategories") 1028 if (key == "notifications_ignoredcategories")
1014 value = (value.indexOf("*") == -1); 1029 value = (value.indexOf("*") == -1);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 { 1080 {
1066 case "app.listen": 1081 case "app.listen":
1067 if (message.action == "addSubscription") 1082 if (message.action == "addSubscription")
1068 { 1083 {
1069 var subscription = message.args[0]; 1084 var subscription = message.args[0];
1070 var dialog = E("dialog-content-predefined"); 1085 var dialog = E("dialog-content-predefined");
1071 dialog.querySelector("h3").textContent = subscription.title || ""; 1086 dialog.querySelector("h3").textContent = subscription.title || "";
1072 dialog.querySelector(".url").textContent = subscription.url; 1087 dialog.querySelector(".url").textContent = subscription.url;
1073 openDialog("predefined"); 1088 openDialog("predefined");
1074 } 1089 }
1075 else if (message.action == "error")
1076 {
1077 alert(message.args.join("\n"));
1078 }
1079 break; 1090 break;
1080 case "filters.listen": 1091 case "filters.listen":
1081 onFilterMessage(message.action, message.args[0]); 1092 onFilterMessage(message.action, message.args[0]);
1082 break; 1093 break;
1083 case "prefs.listen": 1094 case "prefs.listen":
1084 onPrefMessage(message.action, message.args[0]); 1095 onPrefMessage(message.action, message.args[0]);
1085 break; 1096 break;
1086 case "subscriptions.listen": 1097 case "subscriptions.listen":
1087 onSubscriptionMessage(message.action, message.args[0]); 1098 onSubscriptionMessage(message.action, message.args[0]);
1088 break; 1099 break;
1089 } 1100 }
1090 }); 1101 });
1091 1102
1092 ext.backgroundPage.sendMessage( 1103 ext.backgroundPage.sendMessage(
1093 { 1104 {
1094 type: "app.listen", 1105 type: "app.listen",
1095 filter: ["addSubscription", "error"] 1106 filter: ["addSubscription", "error"]
1096 }); 1107 });
1097 ext.backgroundPage.sendMessage( 1108 ext.backgroundPage.sendMessage(
1098 { 1109 {
1099 type: "filters.listen", 1110 type: "filters.listen",
1100 filter: ["added", "loaded", "removed"] 1111 filter: ["added", "loaded", "removed"]
1101 }); 1112 });
1102 ext.backgroundPage.sendMessage( 1113 ext.backgroundPage.sendMessage(
1103 { 1114 {
1104 type: "prefs.listen", 1115 type: "prefs.listen",
1105 filter: ["notifications_ignoredcategories", "notifications_showui", 1116 filter: ["notifications_ignoredcategories", "notifications_showui",
1106 "safari_contentblocker", "shouldShowBlockElementMenu"] 1117 "safari_contentblocker", "show_devtools_panel",
1118 "shouldShowBlockElementMenu"]
1107 }); 1119 });
1108 ext.backgroundPage.sendMessage( 1120 ext.backgroundPage.sendMessage(
1109 { 1121 {
1110 type: "subscriptions.listen", 1122 type: "subscriptions.listen",
1111 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1123 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1124 "title"]
1112 }); 1125 });
1113 1126
1114 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1127 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1115 })(); 1128 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld