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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 { | 519 { |
520 ext.backgroundPage.sendMessage(message, (errors) => | 520 ext.backgroundPage.sendMessage(message, (errors) => |
521 { | 521 { |
522 if (errors.length > 0) | 522 if (errors.length > 0) |
523 alert(errors.join("\n")); | 523 alert(errors.join("\n")); |
524 else if (onSuccess) | 524 else if (onSuccess) |
525 onSuccess(); | 525 onSuccess(); |
526 }); | 526 }); |
527 } | 527 } |
528 | 528 |
529 function openDocLink(id) | |
530 { | |
531 getDocLink(id, (link) => | |
532 { | |
533 if (id == "share-general") | |
534 openSharePopup(link); | |
535 else | |
536 location.href = link; | |
537 }); | |
538 } | |
539 | |
540 function switchTab(id) | 529 function switchTab(id) |
541 { | 530 { |
542 location.hash = id; | 531 location.hash = id; |
543 } | 532 } |
544 | 533 |
545 function execAction(action, element) | 534 function execAction(action, element) |
546 { | 535 { |
547 switch (action) | 536 switch (action) |
548 { | 537 { |
549 case "add-domain-exception": | 538 case "add-domain-exception": |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 let listItem = findParentData(element, "access", true); | 587 let listItem = findParentData(element, "access", true); |
599 if (listItem && !listItem.classList.contains("show-context-menu")) | 588 if (listItem && !listItem.classList.contains("show-context-menu")) |
600 listItem.classList.add("show-context-menu"); | 589 listItem.classList.add("show-context-menu"); |
601 break; | 590 break; |
602 } | 591 } |
603 case "open-dialog": { | 592 case "open-dialog": { |
604 let dialog = findParentData(element, "dialog", false); | 593 let dialog = findParentData(element, "dialog", false); |
605 openDialog(dialog); | 594 openDialog(dialog); |
606 break; | 595 break; |
607 } | 596 } |
608 case "open-doclink": { | |
609 let doclink = findParentData(element, "doclink", false); | |
610 openDocLink(doclink); | |
611 break; | |
612 } | |
613 case "remove-filter": | 597 case "remove-filter": |
614 ext.backgroundPage.sendMessage({ | 598 ext.backgroundPage.sendMessage({ |
615 type: "filters.remove", | 599 type: "filters.remove", |
616 text: findParentData(element, "access", false) | 600 text: findParentData(element, "access", false) |
617 }); | 601 }); |
618 break; | 602 break; |
619 case "remove-subscription": | 603 case "remove-subscription": |
620 ext.backgroundPage.sendMessage({ | 604 ext.backgroundPage.sendMessage({ |
621 type: "subscriptions.remove", | 605 type: "subscriptions.remove", |
622 url: findParentData(element, "access", false) | 606 url: findParentData(element, "access", false) |
(...skipping 16 matching lines...) Expand all Loading... |
639 type: value == "privacy" ? "subscriptions.add" : | 623 type: value == "privacy" ? "subscriptions.add" : |
640 "subscriptions.remove", | 624 "subscriptions.remove", |
641 url: acceptableAdsPrivacyUrl | 625 url: acceptableAdsPrivacyUrl |
642 }); | 626 }); |
643 ext.backgroundPage.sendMessage({ | 627 ext.backgroundPage.sendMessage({ |
644 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", | 628 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", |
645 url: acceptableAdsUrl | 629 url: acceptableAdsUrl |
646 }); | 630 }); |
647 break; | 631 break; |
648 case "switch-tab": | 632 case "switch-tab": |
649 let tabId = findParentData(element, "tab", false); | 633 switchTab(element.getAttribute("href").substr(1)); |
650 switchTab(tabId); | |
651 break; | 634 break; |
652 case "toggle-disable-subscription": | 635 case "toggle-disable-subscription": |
653 ext.backgroundPage.sendMessage({ | 636 ext.backgroundPage.sendMessage({ |
654 type: "subscriptions.toggle", | 637 type: "subscriptions.toggle", |
655 keepInstalled: true, | 638 keepInstalled: true, |
656 url: findParentData(element, "access", false) | 639 url: findParentData(element, "access", false) |
657 }); | 640 }); |
658 break; | 641 break; |
659 case "toggle-pref": | 642 case "toggle-pref": |
660 ext.backgroundPage.sendMessage({ | 643 ext.backgroundPage.sendMessage({ |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 let container = findParentData(element, "action", true); | 736 let container = findParentData(element, "action", true); |
754 if (!container || !container.hasAttribute("data-keys")) | 737 if (!container || !container.hasAttribute("data-keys")) |
755 return; | 738 return; |
756 | 739 |
757 let keys = container.getAttribute("data-keys").split(" "); | 740 let keys = container.getAttribute("data-keys").split(" "); |
758 if (keys.indexOf(key) < 0) | 741 if (keys.indexOf(key) < 0) |
759 return; | 742 return; |
760 | 743 |
761 if (element.getAttribute("role") == "tab") | 744 if (element.getAttribute("role") == "tab") |
762 { | 745 { |
| 746 let parent = element.parentElement; |
763 if (key == "ArrowLeft" || key == "ArrowUp") | 747 if (key == "ArrowLeft" || key == "ArrowUp") |
764 element = element.previousElementSibling || container.lastElementChild; | 748 parent = parent.previousElementSibling || container.lastElementChild; |
765 else if (key == "ArrowRight" || key == "ArrowDown") | 749 else if (key == "ArrowRight" || key == "ArrowDown") |
766 element = element.nextElementSibling || container.firstElementChild; | 750 parent = parent.nextElementSibling || container.firstElementChild; |
| 751 element = parent.firstElementChild; |
767 } | 752 } |
768 | 753 |
769 let actions = container.getAttribute("data-action").split(","); | 754 let actions = container.getAttribute("data-action").split(","); |
770 for (let action of actions) | 755 for (let action of actions) |
771 { | 756 { |
772 execAction(action, element); | 757 execAction(action, element); |
773 } | 758 } |
774 } | 759 } |
775 | 760 |
776 function selectTabItem(tabId, container, focus) | 761 function selectTabItem(tabId, container, focus) |
777 { | 762 { |
778 // Show tab content | 763 // Show tab content |
779 document.body.setAttribute("data-tab", tabId); | 764 document.body.setAttribute("data-tab", tabId); |
780 | 765 |
781 // Select tab | 766 // Select tab |
782 let tabList = container.querySelector("[role='tablist']"); | 767 let tabList = container.querySelector("[role='tablist']"); |
783 if (!tabList) | 768 if (!tabList) |
784 return null; | 769 return null; |
785 | 770 |
786 let previousTab = tabList.querySelector("[aria-selected]"); | 771 let previousTab = tabList.querySelector("[aria-selected]"); |
787 previousTab.removeAttribute("aria-selected"); | 772 previousTab.removeAttribute("aria-selected"); |
788 previousTab.setAttribute("tabindex", -1); | 773 previousTab.setAttribute("tabindex", -1); |
789 | 774 |
790 let tab = tabList.querySelector("li[data-tab='" + tabId + "']"); | 775 let tab = tabList.querySelector("a[href='#" + tabId + "']"); |
791 tab.setAttribute("aria-selected", true); | 776 tab.setAttribute("aria-selected", true); |
792 tab.setAttribute("tabindex", 0); | 777 tab.setAttribute("tabindex", 0); |
793 | 778 |
794 let tabContentId = tab.getAttribute("aria-controls"); | 779 let tabContentId = tab.getAttribute("aria-controls"); |
795 let tabContent = document.getElementById(tabContentId); | 780 let tabContent = document.getElementById(tabContentId); |
796 | 781 |
797 if (tab && focus) | 782 if (tab && focus) |
798 tab.focus(); | 783 tab.focus(); |
799 | 784 |
800 return tabContent; | 785 return tabContent; |
(...skipping 21 matching lines...) Expand all Loading... |
822 { | 807 { |
823 populateLists(); | 808 populateLists(); |
824 | 809 |
825 // Initialize navigation sidebar | 810 // Initialize navigation sidebar |
826 ext.backgroundPage.sendMessage({ | 811 ext.backgroundPage.sendMessage({ |
827 type: "app.get", | 812 type: "app.get", |
828 what: "addonVersion" | 813 what: "addonVersion" |
829 }, | 814 }, |
830 (addonVersion) => | 815 (addonVersion) => |
831 { | 816 { |
832 E("abp-version").textContent = addonVersion; | 817 E("abp-version").textContent = getMessage("options_dialog_about_version", |
833 }); | 818 [addonVersion]); |
834 getDocLink("releases", (link) => | |
835 { | |
836 E("link-version").setAttribute("href", link); | |
837 }); | 819 }); |
838 | 820 |
839 updateShareLink(); | |
840 updateTooltips(); | 821 updateTooltips(); |
841 | 822 |
842 // Initialize interactive UI elements | 823 // Initialize interactive UI elements |
843 document.body.addEventListener("click", onClick, false); | 824 document.body.addEventListener("click", onClick, false); |
844 document.body.addEventListener("keyup", onKeyUp, false); | 825 document.body.addEventListener("keyup", onKeyUp, false); |
845 let exampleValue = getMessage("options_whitelist_placeholder_example", | 826 let exampleValue = getMessage("options_whitelist_placeholder_example", |
846 ["www.example.com"]); | 827 ["www.example.com"]); |
847 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); | 828 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); |
848 E("whitelisting-textbox").addEventListener("keyup", (e) => | 829 E("whitelisting-textbox").addEventListener("keyup", (e) => |
849 { | 830 { |
850 E("whitelisting-add-button").disabled = !e.target.value; | 831 E("whitelisting-add-button").disabled = !e.target.value; |
851 }, false); | 832 }, false); |
852 | 833 |
| 834 |
| 835 getDocLink("contribute", (link) => |
| 836 { |
| 837 E("contribute").href = link; |
| 838 }); |
853 getDocLink("acceptable_ads_criteria", (link) => | 839 getDocLink("acceptable_ads_criteria", (link) => |
854 { | 840 { |
855 setLinks("enable-aa-description", link); | 841 setLinks("enable-aa-description", link); |
856 }); | 842 }); |
857 | 843 |
858 // Advanced tab | 844 // Advanced tab |
859 let customize = document.querySelectorAll("#customize li[data-pref]"); | 845 let customize = document.querySelectorAll("#customize li[data-pref]"); |
860 customize = Array.prototype.map.call(customize, (checkbox) => | 846 customize = Array.prototype.map.call(customize, (checkbox) => |
861 { | 847 { |
862 return checkbox.getAttribute("data-pref"); | 848 return checkbox.getAttribute("data-pref"); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 ext.backgroundPage.sendMessage(message); | 1115 ext.backgroundPage.sendMessage(message); |
1130 } | 1116 } |
1131 | 1117 |
1132 function onFilterMessage(action, filter) | 1118 function onFilterMessage(action, filter) |
1133 { | 1119 { |
1134 switch (action) | 1120 switch (action) |
1135 { | 1121 { |
1136 case "added": | 1122 case "added": |
1137 filter[timestampUI] = Date.now(); | 1123 filter[timestampUI] = Date.now(); |
1138 updateFilter(filter); | 1124 updateFilter(filter); |
1139 updateShareLink(); | |
1140 break; | 1125 break; |
1141 case "loaded": | 1126 case "loaded": |
1142 populateLists(); | 1127 populateLists(); |
1143 break; | 1128 break; |
1144 case "removed": | 1129 case "removed": |
1145 let knownFilter = filtersMap[filter.text]; | 1130 let knownFilter = filtersMap[filter.text]; |
1146 if (whitelistedDomainRegexp.test(knownFilter.text)) | 1131 if (whitelistedDomainRegexp.test(knownFilter.text)) |
1147 collections.whitelist.removeItem(knownFilter); | 1132 collections.whitelist.removeItem(knownFilter); |
1148 else | 1133 else |
1149 removeCustomFilter(filter.text); | 1134 removeCustomFilter(filter.text); |
1150 | 1135 |
1151 delete filtersMap[filter.text]; | 1136 delete filtersMap[filter.text]; |
1152 updateShareLink(); | |
1153 break; | 1137 break; |
1154 } | 1138 } |
1155 } | 1139 } |
1156 | 1140 |
1157 function onSubscriptionMessage(action, subscription) | 1141 function onSubscriptionMessage(action, subscription) |
1158 { | 1142 { |
1159 if (subscription.url in subscriptionsMap) | 1143 if (subscription.url in subscriptionsMap) |
1160 { | 1144 { |
1161 let knownSubscription = subscriptionsMap[subscription.url]; | 1145 let knownSubscription = subscriptionsMap[subscription.url]; |
1162 for (let property in subscription) | 1146 for (let property in subscription) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 } | 1190 } |
1207 else | 1191 else |
1208 { | 1192 { |
1209 collections.custom.removeItem(subscription); | 1193 collections.custom.removeItem(subscription); |
1210 } | 1194 } |
1211 } | 1195 } |
1212 collections.filterLists.removeItem(subscription); | 1196 collections.filterLists.removeItem(subscription); |
1213 break; | 1197 break; |
1214 } | 1198 } |
1215 | 1199 |
1216 updateShareLink(); | |
1217 } | 1200 } |
1218 | 1201 |
1219 function hidePref(key, value) | 1202 function hidePref(key, value) |
1220 { | 1203 { |
1221 let element = document.querySelector("[data-pref='" + key + "']"); | 1204 let element = document.querySelector("[data-pref='" + key + "']"); |
1222 if (element) | 1205 if (element) |
1223 element.setAttribute("aria-hidden", value); | 1206 element.setAttribute("aria-hidden", value); |
1224 } | 1207 } |
1225 | 1208 |
1226 function getPref(key, callback) | 1209 function getPref(key, callback) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 break; | 1250 break; |
1268 } | 1251 } |
1269 | 1252 |
1270 let checkbox = document.querySelector( | 1253 let checkbox = document.querySelector( |
1271 "[data-pref='" + key + "'] button[role='checkbox']" | 1254 "[data-pref='" + key + "'] button[role='checkbox']" |
1272 ); | 1255 ); |
1273 if (checkbox) | 1256 if (checkbox) |
1274 checkbox.setAttribute("aria-checked", value); | 1257 checkbox.setAttribute("aria-checked", value); |
1275 } | 1258 } |
1276 | 1259 |
1277 function updateShareLink() | |
1278 { | |
1279 let shareResources = [ | |
1280 "https://facebook.com/plugins/like.php?", | |
1281 "https://platform.twitter.com/widgets/", | |
1282 "https://apis.google.com/se/0/_/+1/fastbutton?" | |
1283 ]; | |
1284 let isAnyBlocked = false; | |
1285 let checksRemaining = shareResources.length; | |
1286 | |
1287 function onResult(isBlocked) | |
1288 { | |
1289 isAnyBlocked |= isBlocked; | |
1290 if (!--checksRemaining) | |
1291 { | |
1292 // Hide the share tab if a script on the share page would be blocked | |
1293 E("tab-share").hidden = isAnyBlocked; | |
1294 } | |
1295 } | |
1296 | |
1297 for (let sharedResource of shareResources) | |
1298 checkShareResource(sharedResource, onResult); | |
1299 } | |
1300 | |
1301 function updateTooltips() | 1260 function updateTooltips() |
1302 { | 1261 { |
1303 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); | 1262 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); |
1304 for (let anchor of anchors) | 1263 for (let anchor of anchors) |
1305 { | 1264 { |
1306 let id = anchor.getAttribute("data-tooltip"); | 1265 let id = anchor.getAttribute("data-tooltip"); |
1307 | 1266 |
1308 let wrapper = document.createElement("div"); | 1267 let wrapper = document.createElement("div"); |
1309 wrapper.className = "tooltip"; | 1268 wrapper.className = "tooltip"; |
1310 anchor.parentNode.replaceChild(wrapper, anchor); | 1269 anchor.parentNode.replaceChild(wrapper, anchor); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 }); | 1326 }); |
1368 ext.backgroundPage.sendMessage({ | 1327 ext.backgroundPage.sendMessage({ |
1369 type: "subscriptions.listen", | 1328 type: "subscriptions.listen", |
1370 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1329 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1371 "title", "downloadStatus", "downloading"] | 1330 "title", "downloadStatus", "downloading"] |
1372 }); | 1331 }); |
1373 | 1332 |
1374 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1333 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1375 window.addEventListener("hashchange", onHashChange, false); | 1334 window.addEventListener("hashchange", onHashChange, false); |
1376 } | 1335 } |
OLD | NEW |