Left: | ||
Right: |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 { | 543 { |
544 ext.backgroundPage.sendMessage(message, (errors) => | 544 ext.backgroundPage.sendMessage(message, (errors) => |
545 { | 545 { |
546 if (errors.length > 0) | 546 if (errors.length > 0) |
547 alert(errors.join("\n")); | 547 alert(errors.join("\n")); |
548 else if (onSuccess) | 548 else if (onSuccess) |
549 onSuccess(); | 549 onSuccess(); |
550 }); | 550 }); |
551 } | 551 } |
552 | 552 |
553 function openDocLink(id) | |
554 { | |
555 getDocLink(id, (link) => | |
556 { | |
557 if (id == "share-general") | |
558 openSharePopup(link); | |
559 else | |
560 location.href = link; | |
561 }); | |
562 } | |
563 | |
564 function switchTab(id) | 553 function switchTab(id) |
565 { | 554 { |
566 location.hash = id; | 555 location.hash = id; |
567 } | 556 } |
568 | 557 |
569 function execAction(action, element) | 558 function execAction(action, element) |
570 { | 559 { |
571 switch (action) | 560 switch (action) |
572 { | 561 { |
573 case "add-domain-exception": | 562 case "add-domain-exception": |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 let listItem = findParentData(element, "access", true); | 634 let listItem = findParentData(element, "access", true); |
646 if (listItem && !listItem.classList.contains("show-context-menu")) | 635 if (listItem && !listItem.classList.contains("show-context-menu")) |
647 listItem.classList.add("show-context-menu"); | 636 listItem.classList.add("show-context-menu"); |
648 break; | 637 break; |
649 } | 638 } |
650 case "open-dialog": { | 639 case "open-dialog": { |
651 let dialog = findParentData(element, "dialog", false); | 640 let dialog = findParentData(element, "dialog", false); |
652 openDialog(dialog); | 641 openDialog(dialog); |
653 break; | 642 break; |
654 } | 643 } |
655 case "open-doclink": { | |
656 let doclink = findParentData(element, "doclink", false); | |
657 openDocLink(doclink); | |
658 break; | |
659 } | |
660 case "remove-filter": | 644 case "remove-filter": |
661 ext.backgroundPage.sendMessage({ | 645 ext.backgroundPage.sendMessage({ |
662 type: "filters.remove", | 646 type: "filters.remove", |
663 text: findParentData(element, "access", false) | 647 text: findParentData(element, "access", false) |
664 }); | 648 }); |
665 break; | 649 break; |
666 case "remove-subscription": | 650 case "remove-subscription": |
667 ext.backgroundPage.sendMessage({ | 651 ext.backgroundPage.sendMessage({ |
668 type: "subscriptions.remove", | 652 type: "subscriptions.remove", |
669 url: findParentData(element, "access", false) | 653 url: findParentData(element, "access", false) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 element = element.nextElementSibling || container.firstElementChild; | 788 element = element.nextElementSibling || container.firstElementChild; |
805 } | 789 } |
806 | 790 |
807 let actions = container.getAttribute("data-action").split(","); | 791 let actions = container.getAttribute("data-action").split(","); |
808 for (let action of actions) | 792 for (let action of actions) |
809 { | 793 { |
810 execAction(action, element); | 794 execAction(action, element); |
811 } | 795 } |
812 } | 796 } |
813 | 797 |
798 function updateTabLinks() | |
juliandoucette
2017/08/21 14:10:34
NIT: Why not add these HREFs directly to new-optio
saroyanm
2017/08/21 15:20:22
To avoid duplications, we do specify the target in
juliandoucette
2017/08/21 16:07:24
NIT: You could *just* set a.href then and:
tabLis
saroyanm
2017/08/21 16:46:12
I agree with you, I'll change this.
saroyanm
2017/08/23 13:35:45
I've updated the tabs implementation.
| |
799 { | |
800 let tabs = document.querySelectorAll("[role='tab']"); | |
juliandoucette
2017/08/21 14:10:34
NIT: Isn't this asking for trouble? e.g. if we add
saroyanm
2017/08/21 15:20:22
Why is this trouble ? No, this logic I think shoul
juliandoucette
2017/08/21 16:07:24
Acknowledged.
Assuming that you want this to happ
| |
801 for (let i = 0; i < tabs.length; i++) | |
802 tabs[i].querySelector("a").href = "#" + tabs[i].dataset.tab; | |
803 } | |
804 | |
814 function selectTabItem(tabId, container, focus) | 805 function selectTabItem(tabId, container, focus) |
815 { | 806 { |
816 // Show tab content | 807 // Show tab content |
817 document.body.setAttribute("data-tab", tabId); | 808 document.body.setAttribute("data-tab", tabId); |
818 | 809 |
819 // Select tab | 810 // Select tab |
820 let tabList = container.querySelector("[role='tablist']"); | 811 let tabList = container.querySelector("[role='tablist']"); |
821 if (!tabList) | 812 if (!tabList) |
822 return null; | 813 return null; |
823 | 814 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 { | 851 { |
861 populateLists(); | 852 populateLists(); |
862 | 853 |
863 // Initialize navigation sidebar | 854 // Initialize navigation sidebar |
864 ext.backgroundPage.sendMessage({ | 855 ext.backgroundPage.sendMessage({ |
865 type: "app.get", | 856 type: "app.get", |
866 what: "addonVersion" | 857 what: "addonVersion" |
867 }, | 858 }, |
868 (addonVersion) => | 859 (addonVersion) => |
869 { | 860 { |
870 E("abp-version").textContent = addonVersion; | 861 E("abp-version").textContent = getMessage("options_dialog_about_version", |
871 }); | 862 [addonVersion]); |
872 getDocLink("releases", (link) => | |
873 { | |
874 E("link-version").setAttribute("href", link); | |
875 }); | 863 }); |
876 | 864 |
877 updateShareLink(); | |
878 updateTooltips(); | 865 updateTooltips(); |
866 updateTabLinks(); | |
879 | 867 |
880 // Initialize interactive UI elements | 868 // Initialize interactive UI elements |
881 document.body.addEventListener("click", onClick, false); | 869 document.body.addEventListener("click", onClick, false); |
882 document.body.addEventListener("keyup", onKeyUp, false); | 870 document.body.addEventListener("keyup", onKeyUp, false); |
883 let exampleValue = getMessage("options_whitelist_placeholder_example", | 871 let exampleValue = getMessage("options_whitelist_placeholder_example", |
884 ["www.example.com"]); | 872 ["www.example.com"]); |
885 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); | 873 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); |
886 E("whitelisting-textbox").addEventListener("keyup", (e) => | 874 E("whitelisting-textbox").addEventListener("keyup", (e) => |
887 { | 875 { |
888 E("whitelisting-add-button").disabled = !e.target.value; | 876 E("whitelisting-add-button").disabled = !e.target.value; |
889 }, false); | 877 }, false); |
890 | 878 |
879 | |
880 getDocLink("contribute", (link) => | |
juliandoucette
2017/08/21 14:10:34
NIT: It seems like these should be batched somewhe
saroyanm
2017/08/21 15:20:22
Yes it's a plan for future. We might also have a t
juliandoucette
2017/08/21 16:07:25
Acknowledged.
Will you check this?
saroyanm
2017/08/21 16:46:13
https://issues.adblockplus.org/ticket/4856
juliandoucette
2017/08/22 10:10:44
Acknowledged.
| |
881 { | |
882 E("contribute").href = link; | |
883 }); | |
891 getDocLink("acceptable_ads_criteria", (link) => | 884 getDocLink("acceptable_ads_criteria", (link) => |
892 { | 885 { |
893 setLinks("enable-aa-description", link); | 886 setLinks("enable-aa-description", link); |
894 }); | 887 }); |
895 | 888 |
896 // Advanced tab | 889 // Advanced tab |
897 let customize = document.querySelectorAll("#customize li[data-pref]"); | 890 let customize = document.querySelectorAll("#customize li[data-pref]"); |
898 customize = Array.prototype.map.call(customize, (checkbox) => | 891 customize = Array.prototype.map.call(customize, (checkbox) => |
899 { | 892 { |
900 return checkbox.getAttribute("data-pref"); | 893 return checkbox.getAttribute("data-pref"); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 ext.backgroundPage.sendMessage(message); | 1149 ext.backgroundPage.sendMessage(message); |
1157 } | 1150 } |
1158 | 1151 |
1159 function onFilterMessage(action, filter) | 1152 function onFilterMessage(action, filter) |
1160 { | 1153 { |
1161 switch (action) | 1154 switch (action) |
1162 { | 1155 { |
1163 case "added": | 1156 case "added": |
1164 filter[timestampUI] = Date.now(); | 1157 filter[timestampUI] = Date.now(); |
1165 updateFilter(filter); | 1158 updateFilter(filter); |
1166 updateShareLink(); | |
1167 break; | 1159 break; |
1168 case "loaded": | 1160 case "loaded": |
1169 populateLists(); | 1161 populateLists(); |
1170 break; | 1162 break; |
1171 case "removed": | 1163 case "removed": |
1172 let knownFilter = filtersMap[filter.text]; | 1164 let knownFilter = filtersMap[filter.text]; |
1173 if (whitelistedDomainRegexp.test(knownFilter.text)) | 1165 if (whitelistedDomainRegexp.test(knownFilter.text)) |
1174 collections.whitelist.removeItem(knownFilter); | 1166 collections.whitelist.removeItem(knownFilter); |
1175 else | 1167 else |
1176 removeCustomFilter(filter.text); | 1168 removeCustomFilter(filter.text); |
1177 | 1169 |
1178 delete filtersMap[filter.text]; | 1170 delete filtersMap[filter.text]; |
1179 updateShareLink(); | |
1180 break; | 1171 break; |
1181 } | 1172 } |
1182 } | 1173 } |
1183 | 1174 |
1184 function onSubscriptionMessage(action, subscription) | 1175 function onSubscriptionMessage(action, subscription) |
1185 { | 1176 { |
1186 if (subscription.url in subscriptionsMap) | 1177 if (subscription.url in subscriptionsMap) |
1187 { | 1178 { |
1188 let knownSubscription = subscriptionsMap[subscription.url]; | 1179 let knownSubscription = subscriptionsMap[subscription.url]; |
1189 for (let property in subscription) | 1180 for (let property in subscription) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 } | 1228 } |
1238 else | 1229 else |
1239 { | 1230 { |
1240 collections.custom.removeItem(subscription); | 1231 collections.custom.removeItem(subscription); |
1241 delete subscriptionsMap[subscription.url]; | 1232 delete subscriptionsMap[subscription.url]; |
1242 } | 1233 } |
1243 collections.filterLists.removeItem(subscription); | 1234 collections.filterLists.removeItem(subscription); |
1244 break; | 1235 break; |
1245 } | 1236 } |
1246 | 1237 |
1247 updateShareLink(); | |
1248 } | 1238 } |
1249 | 1239 |
1250 function hidePref(key, value) | 1240 function hidePref(key, value) |
1251 { | 1241 { |
1252 let element = document.querySelector("[data-pref='" + key + "']"); | 1242 let element = document.querySelector("[data-pref='" + key + "']"); |
1253 if (element) | 1243 if (element) |
1254 element.setAttribute("aria-hidden", value); | 1244 element.setAttribute("aria-hidden", value); |
1255 } | 1245 } |
1256 | 1246 |
1257 function getPref(key, callback) | 1247 function getPref(key, callback) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1298 break; | 1288 break; |
1299 } | 1289 } |
1300 | 1290 |
1301 let checkbox = document.querySelector( | 1291 let checkbox = document.querySelector( |
1302 "[data-pref='" + key + "'] button[role='checkbox']" | 1292 "[data-pref='" + key + "'] button[role='checkbox']" |
1303 ); | 1293 ); |
1304 if (checkbox) | 1294 if (checkbox) |
1305 checkbox.setAttribute("aria-checked", value); | 1295 checkbox.setAttribute("aria-checked", value); |
1306 } | 1296 } |
1307 | 1297 |
1308 function updateShareLink() | |
1309 { | |
1310 let shareResources = [ | |
1311 "https://facebook.com/plugins/like.php?", | |
1312 "https://platform.twitter.com/widgets/", | |
1313 "https://apis.google.com/se/0/_/+1/fastbutton?" | |
1314 ]; | |
1315 let isAnyBlocked = false; | |
1316 let checksRemaining = shareResources.length; | |
1317 | |
1318 function onResult(isBlocked) | |
1319 { | |
1320 isAnyBlocked |= isBlocked; | |
1321 if (!--checksRemaining) | |
1322 { | |
1323 // Hide the share tab if a script on the share page would be blocked | |
1324 E("tab-share").hidden = isAnyBlocked; | |
1325 } | |
1326 } | |
1327 | |
1328 for (let sharedResource of shareResources) | |
1329 checkShareResource(sharedResource, onResult); | |
1330 } | |
1331 | |
1332 function getMessages(id) | 1298 function getMessages(id) |
1333 { | 1299 { |
1334 let messages = []; | 1300 let messages = []; |
1335 for (let i = 1; true; i++) | 1301 for (let i = 1; true; i++) |
1336 { | 1302 { |
1337 let message = ext.i18n.getMessage(id + "_" + i); | 1303 let message = ext.i18n.getMessage(id + "_" + i); |
1338 if (!message) | 1304 if (!message) |
1339 break; | 1305 break; |
1340 | 1306 |
1341 messages.push(message); | 1307 messages.push(message); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1448 }); | 1414 }); |
1449 ext.backgroundPage.sendMessage({ | 1415 ext.backgroundPage.sendMessage({ |
1450 type: "subscriptions.listen", | 1416 type: "subscriptions.listen", |
1451 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1417 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1452 "title", "downloadStatus", "downloading"] | 1418 "title", "downloadStatus", "downloading"] |
1453 }); | 1419 }); |
1454 | 1420 |
1455 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1421 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1456 window.addEventListener("hashchange", onHashChange, false); | 1422 window.addEventListener("hashchange", onHashChange, false); |
1457 } | 1423 } |
OLD | NEW |