| 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-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, onMessage) | 550 function sendMessageHandleErrors(message, callback) |
|
saroyanm
2018/01/23 15:26:06
Suggestion/detail: seems like onMessage is used fo
| |
| 551 { | 551 { |
| 552 browser.runtime.sendMessage(message, (errors) => | 552 browser.runtime.sendMessage(message, (errors) => |
| 553 { | 553 { |
| 554 if (onMessage) | 554 if (callback) |
| 555 { | 555 { |
| 556 if (errors.length > 0) | 556 if (errors.length > 0) |
| 557 onMessage(errors); | 557 callback(errors); |
| 558 else | 558 else |
| 559 onMessage(); | 559 callback(); |
| 560 } | 560 } |
| 561 }); | 561 }); |
| 562 } | 562 } |
| 563 | 563 |
| 564 function switchTab(id) | 564 function switchTab(id) |
| 565 { | 565 { |
| 566 location.hash = id; | 566 location.hash = id; |
| 567 } | 567 } |
| 568 | 568 |
| 569 function execAction(action, element) | 569 function execAction(action, element) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 text: findParentData(element, "access", false) | 644 text: findParentData(element, "access", false) |
| 645 }); | 645 }); |
| 646 break; | 646 break; |
| 647 case "remove-subscription": | 647 case "remove-subscription": |
| 648 browser.runtime.sendMessage({ | 648 browser.runtime.sendMessage({ |
| 649 type: "subscriptions.remove", | 649 type: "subscriptions.remove", |
| 650 url: findParentData(element, "access", false) | 650 url: findParentData(element, "access", false) |
| 651 }); | 651 }); |
| 652 break; | 652 break; |
| 653 case "save-custom-filters": | 653 case "save-custom-filters": |
| 654 const filters = E("custom-filters-raw"); | 654 const filters = E("custom-filters-raw").value; |
| 655 sendMessageHandleErrors({ | 655 sendMessageHandleErrors({ |
| 656 type: "filters.importRaw", | 656 type: "filters.importRaw", |
| 657 text: filters.value, | 657 text: filters, |
| 658 removeExisting: true | 658 removeExisting: true |
| 659 }, | 659 }, |
| 660 (errors) => | 660 (errors) => |
| 661 { | 661 { |
| 662 if (errors) | 662 if (errors) |
| 663 { | 663 { |
| 664 filters.classList.add("warning"); | 664 E("custom-filters").classList.add("warning"); |
| 665 E("custom-filters-edit-error").classList.add("warning"); | 665 const customFiltersError = clearAndGetCustomFiltersError(); |
|
saroyanm
2018/01/23 15:26:06
Suggestion: I think we can use "custom-filters" in
| |
| 666 E("link-filters-on-edit-error").classList.add("visible"); | 666 |
|
saroyanm
2018/01/23 15:26:06
Note: If we agree on making this message persisten
| |
| 667 const lines = filters.value.split(/\n+/); | 667 // The current error does not contain info about the line |
| 668 const info = errors.map(error => lines[error.lineno - 1]); | 668 // that generated such error. |
|
saroyanm
2018/01/23 15:26:05
Note: As soon we introduce a new functionality whi
saroyanm
2018/01/23 15:26:06
I think would be great if we could return the filt
a.giammarchi
2018/01/23 15:43:18
yup, that's the "there's surely still stuff to do
a.giammarchi
2018/01/23 15:59:23
about this ... the error object doesn't offer much
saroyanm
2018/01/24 09:05:49
I think I couldn't well describe what I meant:
sen
| |
| 669 const editFilters = E("custom-filters-edit-filters"); | 669 // Whenever the error object will pass the bad filter |
| 670 editFilters.textContent = info.join("\n"); | 670 // within its properties, this split should be removed. |
|
saroyanm
2018/01/23 15:26:05
Adding all the elements as a textContent to div ma
a.giammarchi
2018/01/23 15:43:18
I either follow UI or I don't ... this comment is
saroyanm
2018/01/23 17:37:18
I missed that, I didn't review the CSS, my fault.
| |
| 671 const lines = filters.split("\n"); | |
| 672 const messages = errors.map(error => lines[error.lineno - 1]); | |
| 673 for (const message of messages) | |
| 674 { | |
| 675 const li = document.createElement("li"); | |
| 676 customFiltersError.appendChild(li).textContent = message; | |
| 677 } | |
| 671 if (errors.length > 5) | 678 if (errors.length > 5) |
| 672 editFilters.classList.add("many"); | 679 customFiltersError.classList.add("many"); |
| 673 } | 680 } |
| 674 else | 681 else |
| 675 { | 682 { |
| 676 setCustomFiltersView("read"); | 683 setCustomFiltersView("read"); |
| 677 } | 684 } |
| 678 }); | 685 }); |
| 679 break; | 686 break; |
| 680 case "show-more-filters-section": | 687 case "show-more-filters-section": |
| 681 E("more-filters").setAttribute("aria-hidden", false); | 688 E("more-filters").setAttribute("aria-hidden", false); |
| 682 break; | 689 break; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 761 closeDialog(); | 768 closeDialog(); |
| 762 } | 769 } |
| 763 else | 770 else |
| 764 { | 771 { |
| 765 form.querySelector(":invalid").focus(); | 772 form.querySelector(":invalid").focus(); |
| 766 } | 773 } |
| 767 break; | 774 break; |
| 768 } | 775 } |
| 769 } | 776 } |
| 770 | 777 |
| 778 function clearAndGetCustomFiltersError() | |
| 779 { | |
| 780 const customFiltersError = E("custom-filters-error"); | |
| 781 customFiltersError.textContent = ""; | |
| 782 customFiltersError.classList.remove("many"); | |
| 783 return customFiltersError; | |
| 784 } | |
| 785 | |
| 771 function setCustomFiltersView(mode) | 786 function setCustomFiltersView(mode) |
| 772 { | 787 { |
| 773 let customFiltersElement = E("custom-filters-raw"); | 788 let customFiltersElement = E("custom-filters-raw"); |
| 774 updateCustomFiltersUi(); | 789 updateCustomFiltersUi(); |
| 775 if (mode == "read") | 790 if (mode == "read") |
| 776 { | 791 { |
| 777 E("custom-filters-raw").classList.remove("warning"); | 792 E("custom-filters").classList.remove("warning"); |
|
saroyanm
2018/01/23 15:26:06
Note: As mentioned above we don't need to remove t
| |
| 778 E("custom-filters-edit-error").classList.remove("warning"); | 793 clearAndGetCustomFiltersError(); |
| 779 E("link-filters-on-edit-error").classList.remove("visible"); | |
| 780 const editFilters = E("custom-filters-edit-filters"); | |
| 781 editFilters.textContent = ""; | |
| 782 editFilters.classList.remove("many"); | |
| 783 customFiltersElement.disabled = true; | 794 customFiltersElement.disabled = true; |
| 784 if (!customFiltersElement.value) | 795 if (!customFiltersElement.value) |
| 785 { | 796 { |
| 786 setCustomFiltersView("empty"); | 797 setCustomFiltersView("empty"); |
| 787 return; | 798 return; |
| 788 } | 799 } |
| 789 } | 800 } |
| 790 else if (mode == "write") | 801 else if (mode == "write") |
| 791 { | 802 { |
| 792 customFiltersElement.disabled = false; | 803 customFiltersElement.disabled = false; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 981 type: "app.get", | 992 type: "app.get", |
| 982 what: "features" | 993 what: "features" |
| 983 }, | 994 }, |
| 984 (features) => | 995 (features) => |
| 985 { | 996 { |
| 986 hidePref("show_devtools_panel", !features.devToolsPanel); | 997 hidePref("show_devtools_panel", !features.devToolsPanel); |
| 987 }); | 998 }); |
| 988 | 999 |
| 989 getDocLink("filterdoc", (link) => | 1000 getDocLink("filterdoc", (link) => |
| 990 { | 1001 { |
| 991 E("link-filters").setAttribute("href", link); | 1002 E("link-filters-1").setAttribute("href", link); |
| 992 E("link-filters-on-edit-error").setAttribute("href", link); | 1003 E("link-filters-2").setAttribute("href", link); |
| 993 }); | 1004 }); |
| 994 | 1005 |
| 995 getDocLink("subscriptions", (link) => | 1006 getDocLink("subscriptions", (link) => |
| 996 { | 1007 { |
| 997 E("filter-lists-learn-more").setAttribute("href", link); | 1008 E("filter-lists-learn-more").setAttribute("href", link); |
| 998 }); | 1009 }); |
| 999 | 1010 |
| 1000 E("custom-filters-raw").setAttribute("placeholder", | 1011 E("custom-filters-raw").setAttribute("placeholder", |
| 1001 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); | 1012 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); |
| 1002 | 1013 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 special: true | 1188 special: true |
| 1178 }, | 1189 }, |
| 1179 (subscriptions) => | 1190 (subscriptions) => |
| 1180 { | 1191 { |
| 1181 // Load filters | 1192 // Load filters |
| 1182 for (let subscription of subscriptions) | 1193 for (let subscription of subscriptions) |
| 1183 { | 1194 { |
| 1184 browser.runtime.sendMessage({ | 1195 browser.runtime.sendMessage({ |
| 1185 type: "filters.get", | 1196 type: "filters.get", |
| 1186 subscriptionUrl: subscription.url | 1197 subscriptionUrl: subscription.url |
| 1187 }, | 1198 }, loadCustomFilters); |
| 1188 (filters) => | |
| 1189 { | |
| 1190 loadCustomFilters(filters); | |
| 1191 }); | |
| 1192 } | 1199 } |
| 1193 }); | 1200 }); |
| 1194 loadRecommendations(); | 1201 loadRecommendations(); |
| 1195 browser.runtime.sendMessage({ | 1202 browser.runtime.sendMessage({ |
| 1196 type: "prefs.get", | 1203 type: "prefs.get", |
| 1197 key: "subscriptions_exceptionsurl" | 1204 key: "subscriptions_exceptionsurl" |
| 1198 }, | 1205 }, |
| 1199 (url) => | 1206 (url) => |
| 1200 { | 1207 { |
| 1201 acceptableAdsUrl = url; | 1208 acceptableAdsUrl = url; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1495 }); | 1502 }); |
| 1496 browser.runtime.sendMessage({ | 1503 browser.runtime.sendMessage({ |
| 1497 type: "subscriptions.listen", | 1504 type: "subscriptions.listen", |
| 1498 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1505 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
| 1499 "title", "downloadStatus", "downloading"] | 1506 "title", "downloadStatus", "downloading"] |
| 1500 }); | 1507 }); |
| 1501 | 1508 |
| 1502 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1509 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 1503 window.addEventListener("hashchange", onHashChange, false); | 1510 window.addEventListener("hashchange", onHashChange, false); |
| 1504 } | 1511 } |
| LEFT | RIGHT |