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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 if (returnElement) | 540 if (returnElement) |
541 return element; | 541 return element; |
542 return element.getAttribute("data-" + dataName); | 542 return element.getAttribute("data-" + dataName); |
543 } | 543 } |
544 | 544 |
545 element = element.parentElement; | 545 element = element.parentElement; |
546 } | 546 } |
547 return null; | 547 return null; |
548 } | 548 } |
549 | 549 |
550 function sendMessageHandleErrors(message, onSuccess) | 550 function sendMessageHandleErrors(message, onMessage) |
551 { | 551 { |
552 browser.runtime.sendMessage(message, (errors) => | 552 browser.runtime.sendMessage(message, (errors) => |
553 { | 553 { |
554 if (errors.length > 0) | 554 if (onMessage) |
555 alert(errors.join("\n")); | 555 { |
556 else if (onSuccess) | 556 if (errors.length > 0) onMessage(errors); |
557 onSuccess(); | 557 else onMessage(); |
| 558 } |
558 }); | 559 }); |
559 } | 560 } |
560 | 561 |
561 function switchTab(id) | 562 function switchTab(id) |
562 { | 563 { |
563 location.hash = id; | 564 location.hash = id; |
564 } | 565 } |
565 | 566 |
566 function execAction(action, element) | 567 function execAction(action, element) |
567 { | 568 { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 text: findParentData(element, "access", false) | 642 text: findParentData(element, "access", false) |
642 }); | 643 }); |
643 break; | 644 break; |
644 case "remove-subscription": | 645 case "remove-subscription": |
645 browser.runtime.sendMessage({ | 646 browser.runtime.sendMessage({ |
646 type: "subscriptions.remove", | 647 type: "subscriptions.remove", |
647 url: findParentData(element, "access", false) | 648 url: findParentData(element, "access", false) |
648 }); | 649 }); |
649 break; | 650 break; |
650 case "save-custom-filters": | 651 case "save-custom-filters": |
| 652 const filters = E("custom-filters-raw"); |
651 sendMessageHandleErrors({ | 653 sendMessageHandleErrors({ |
652 type: "filters.importRaw", | 654 type: "filters.importRaw", |
653 text: E("custom-filters-raw").value, | 655 text: filters.value, |
654 removeExisting: true | 656 removeExisting: true |
655 }, | 657 }, |
656 () => | 658 (errors) => |
657 { | 659 { |
658 setCustomFiltersView("read"); | 660 if (errors) |
| 661 { |
| 662 filters.classList.add("warning"); |
| 663 E("custom-filters-edit-error").classList.add("warning"); |
| 664 E("link-filters-on-edit-error").classList.add("visible"); |
| 665 const lines = filters.value.split(/\n+/); |
| 666 const info = errors.map(error => lines[error.lineno - 1]); |
| 667 const editFilters = E("custom-filters-edit-filters"); |
| 668 editFilters.textContent = info.join("\n"); |
| 669 if (errors.length > 5) editFilters.classList.add("many"); |
| 670 } |
| 671 else |
| 672 { |
| 673 setCustomFiltersView("read"); |
| 674 } |
659 }); | 675 }); |
660 break; | 676 break; |
661 case "show-more-filters-section": | 677 case "show-more-filters-section": |
662 E("more-filters").setAttribute("aria-hidden", false); | 678 E("more-filters").setAttribute("aria-hidden", false); |
663 break; | 679 break; |
664 case "switch-acceptable-ads": | 680 case "switch-acceptable-ads": |
665 let value = element.value || element.dataset.value; | 681 let value = element.value || element.dataset.value; |
666 // User check the checkbox | 682 // User check the checkbox |
667 let shouldCheck = element.getAttribute("aria-checked") != "true"; | 683 let shouldCheck = element.getAttribute("aria-checked") != "true"; |
668 let installAcceptableAds = false; | 684 let installAcceptableAds = false; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 break; | 764 break; |
749 } | 765 } |
750 } | 766 } |
751 | 767 |
752 function setCustomFiltersView(mode) | 768 function setCustomFiltersView(mode) |
753 { | 769 { |
754 let customFiltersElement = E("custom-filters-raw"); | 770 let customFiltersElement = E("custom-filters-raw"); |
755 updateCustomFiltersUi(); | 771 updateCustomFiltersUi(); |
756 if (mode == "read") | 772 if (mode == "read") |
757 { | 773 { |
| 774 E("custom-filters-raw").classList.remove("warning"); |
| 775 E("custom-filters-edit-error").classList.remove("warning"); |
| 776 E("link-filters-on-edit-error").classList.remove("visible"); |
| 777 const editFilters = E("custom-filters-edit-filters"); |
| 778 editFilters.textContent = ""; |
| 779 editFilters.classList.remove("many"); |
758 customFiltersElement.disabled = true; | 780 customFiltersElement.disabled = true; |
759 if (!customFiltersElement.value) | 781 if (!customFiltersElement.value) |
760 { | 782 { |
761 setCustomFiltersView("empty"); | 783 setCustomFiltersView("empty"); |
762 return; | 784 return; |
763 } | 785 } |
764 } | 786 } |
765 else if (mode == "write") | 787 else if (mode == "write") |
766 { | 788 { |
767 customFiltersElement.disabled = false; | 789 customFiltersElement.disabled = false; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 | 933 |
912 // General tab | 934 // General tab |
913 getDocLink("contribute", (link) => | 935 getDocLink("contribute", (link) => |
914 { | 936 { |
915 E("contribute").href = link; | 937 E("contribute").href = link; |
916 }); | 938 }); |
917 getDocLink("acceptable_ads_criteria", (link) => | 939 getDocLink("acceptable_ads_criteria", (link) => |
918 { | 940 { |
919 setLinks("enable-acceptable-ads-description", link); | 941 setLinks("enable-acceptable-ads-description", link); |
920 }); | 942 }); |
921 setElementText(E("tracking-warning-1"), "options_tracking_warning_1", | 943 setElementText(E("tracking-warning-1"), "options_tracking_warning_1", |
922 [getMessage("common_feature_privacy_title"), | 944 [getMessage("common_feature_privacy_title"), |
923 getMessage("options_acceptableAds_ads_label")]); | 945 getMessage("options_acceptableAds_ads_label")]); |
924 setElementText(E("tracking-warning-3"), "options_tracking_warning_3", | 946 setElementText(E("tracking-warning-3"), "options_tracking_warning_3", |
925 [getMessage("options_acceptableAds_privacy_label")]); | 947 [getMessage("options_acceptableAds_privacy_label")]); |
926 | 948 |
927 getDocLink("privacy_friendly_ads", (link) => | 949 getDocLink("privacy_friendly_ads", (link) => |
928 { | 950 { |
929 E("enable-acceptable-ads-privacy-description").href = link; | 951 E("enable-acceptable-ads-privacy-description").href = link; |
930 }); | 952 }); |
931 getDocLink("adblock_plus_{browser}_dnt", url => | 953 getDocLink("adblock_plus_{browser}_dnt", url => |
932 { | 954 { |
933 setLinks("dnt", url); | 955 setLinks("dnt", url); |
934 }); | 956 }); |
(...skipping 22 matching lines...) Expand all Loading... |
957 what: "features" | 979 what: "features" |
958 }, | 980 }, |
959 (features) => | 981 (features) => |
960 { | 982 { |
961 hidePref("show_devtools_panel", !features.devToolsPanel); | 983 hidePref("show_devtools_panel", !features.devToolsPanel); |
962 }); | 984 }); |
963 | 985 |
964 getDocLink("filterdoc", (link) => | 986 getDocLink("filterdoc", (link) => |
965 { | 987 { |
966 E("link-filters").setAttribute("href", link); | 988 E("link-filters").setAttribute("href", link); |
| 989 E("link-filters-on-edit-error").setAttribute("href", link); |
967 }); | 990 }); |
968 | 991 |
969 getDocLink("subscriptions", (link) => | 992 getDocLink("subscriptions", (link) => |
970 { | 993 { |
971 E("filter-lists-learn-more").setAttribute("href", link); | 994 E("filter-lists-learn-more").setAttribute("href", link); |
972 }); | 995 }); |
973 | 996 |
974 E("custom-filters-raw").setAttribute("placeholder", | 997 E("custom-filters-raw").setAttribute("placeholder", |
975 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); | 998 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); |
976 | 999 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 setPrivacyConflict(); | 1311 setPrivacyConflict(); |
1289 break; | 1312 break; |
1290 case "downloading": | 1313 case "downloading": |
1291 case "downloadStatus": | 1314 case "downloadStatus": |
1292 case "homepage": | 1315 case "homepage": |
1293 case "lastDownload": | 1316 case "lastDownload": |
1294 case "title": | 1317 case "title": |
1295 updateSubscription(subscription); | 1318 updateSubscription(subscription); |
1296 break; | 1319 break; |
1297 case "added": | 1320 case "added": |
1298 let {url, recommended} = subscription; | 1321 let {url} = subscription; |
1299 // Handle custom subscription | 1322 // Handle custom subscription |
1300 if (/^~user/.test(url)) | 1323 if (/^~user/.test(url)) |
1301 { | 1324 { |
1302 loadCustomFilters(subscription.filters); | 1325 loadCustomFilters(subscription.filters); |
1303 return; | 1326 return; |
1304 } | 1327 } |
1305 else if (url in subscriptionsMap) | 1328 else if (url in subscriptionsMap) |
1306 updateSubscription(subscription); | 1329 updateSubscription(subscription); |
1307 else | 1330 else |
1308 addSubscription(subscription); | 1331 addSubscription(subscription); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 }); | 1492 }); |
1470 browser.runtime.sendMessage({ | 1493 browser.runtime.sendMessage({ |
1471 type: "subscriptions.listen", | 1494 type: "subscriptions.listen", |
1472 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1495 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1473 "title", "downloadStatus", "downloading"] | 1496 "title", "downloadStatus", "downloading"] |
1474 }); | 1497 }); |
1475 | 1498 |
1476 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1499 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1477 window.addEventListener("hashchange", onHashChange, false); | 1500 window.addEventListener("hashchange", onHashChange, false); |
1478 } | 1501 } |
OLD | NEW |