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-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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
| 18 /* globals checkShareResource, getDocLink, openSharePopup, E */ |
| 19 |
18 "use strict"; | 20 "use strict"; |
19 | 21 |
20 (function() | |
21 { | 22 { |
22 function onDOMLoaded() | 23 function onDOMLoaded() |
23 { | 24 { |
24 // Set up logo image | 25 // Set up logo image |
25 var logo = E("logo"); | 26 let logo = E("logo"); |
26 logo.src = "skin/abp-128.png"; | 27 logo.src = "skin/abp-128.png"; |
27 var errorCallback = function() | 28 let errorCallback = function() |
28 { | 29 { |
29 logo.removeEventListener("error", errorCallback, false); | 30 logo.removeEventListener("error", errorCallback, false); |
30 // We are probably in Chrome/Opera/Safari, the image has a different path. | 31 // We are probably in Chrome/Opera/Safari, the image has a different path. |
31 logo.src = "icons/detailed/abp-128.png"; | 32 logo.src = "icons/detailed/abp-128.png"; |
32 }; | 33 }; |
33 logo.addEventListener("error", errorCallback, false); | 34 logo.addEventListener("error", errorCallback, false); |
34 | 35 |
35 // Set up URLs | 36 // Set up URLs |
36 getDocLink("donate", function(link) | 37 getDocLink("donate", link => |
37 { | 38 { |
38 E("donate").href = link; | 39 E("donate").href = link; |
39 }); | 40 }); |
40 | 41 |
41 getDocLink("contributors", function(link) | 42 getDocLink("contributors", link => |
42 { | 43 { |
43 E("contributors").href = link; | 44 E("contributors").href = link; |
44 }); | 45 }); |
45 | 46 |
46 getDocLink("acceptable_ads_criteria", function(link) | 47 getDocLink("acceptable_ads_criteria", link => |
47 { | 48 { |
48 setLinks("acceptable-ads-explanation", link, openFilters); | 49 setLinks("acceptable-ads-explanation", link, openFilters); |
49 }); | 50 }); |
50 | 51 |
51 getDocLink("contribute", function(link) | 52 getDocLink("contribute", link => |
52 { | 53 { |
53 setLinks("share-headline", link); | 54 setLinks("share-headline", link); |
54 }); | 55 }); |
55 | 56 |
56 ext.backgroundPage.sendMessage({ | 57 ext.backgroundPage.sendMessage({ |
57 type: "app.get", | 58 type: "app.get", |
58 what: "issues" | 59 what: "issues" |
59 }, function(issues) | 60 }, issues => |
60 { | 61 { |
61 // Show warning if filterlists settings were reinitialized | 62 // Show warning if filterlists settings were reinitialized |
62 if (issues.filterlistsReinitialized) | 63 if (issues.filterlistsReinitialized) |
63 { | 64 { |
64 E("filterlistsReinitializedWarning").removeAttribute("hidden"); | 65 E("filterlistsReinitializedWarning").removeAttribute("hidden"); |
65 setLinks("filterlistsReinitializedWarning", openFilters); | 66 setLinks("filterlistsReinitializedWarning", openFilters); |
66 } | 67 } |
67 }); | 68 }); |
68 | 69 |
69 updateSocialLinks(); | 70 updateSocialLinks(); |
70 | 71 |
71 ext.onMessage.addListener(function(message) | 72 ext.onMessage.addListener(message => |
72 { | 73 { |
73 if (message.type == "subscriptions.respond") | 74 if (message.type == "subscriptions.respond") |
74 { | |
75 updateSocialLinks(); | 75 updateSocialLinks(); |
76 } | |
77 }); | 76 }); |
78 ext.backgroundPage.sendMessage({ | 77 ext.backgroundPage.sendMessage({ |
79 type: "subscriptions.listen", | 78 type: "subscriptions.listen", |
80 filter: ["added", "removed", "updated", "disabled"] | 79 filter: ["added", "removed", "updated", "disabled"] |
81 }); | 80 }); |
82 } | 81 } |
83 | 82 |
84 function updateSocialLinks() | 83 function updateSocialLinks() |
85 { | 84 { |
86 var networks = ["twitter", "facebook", "gplus"]; | 85 for (let network of ["twitter", "facebook", "gplus"]) |
87 networks.forEach(function(network) | |
88 { | 86 { |
89 var link = E("share-" + network); | 87 let link = E("share-" + network); |
90 checkShareResource(link.getAttribute("data-script"), function(isBlocked) | 88 checkShareResource(link.getAttribute("data-script"), isBlocked => |
91 { | 89 { |
92 // Don't open the share page if the sharing script would be blocked | 90 // Don't open the share page if the sharing script would be blocked |
93 if (isBlocked) | 91 if (isBlocked) |
94 link.removeEventListener("click", onSocialLinkClick, false); | 92 link.removeEventListener("click", onSocialLinkClick, false); |
95 else | 93 else |
96 link.addEventListener("click", onSocialLinkClick, false); | 94 link.addEventListener("click", onSocialLinkClick, false); |
97 }); | 95 }); |
98 }); | 96 } |
99 } | 97 } |
100 | 98 |
101 function onSocialLinkClick(event) | 99 function onSocialLinkClick(event) |
102 { | 100 { |
103 if (window.matchMedia("(max-width: 970px)").matches) | 101 if (window.matchMedia("(max-width: 970px)").matches) |
104 return; | 102 return; |
105 | 103 |
106 event.preventDefault(); | 104 event.preventDefault(); |
107 | 105 |
108 getDocLink(event.target.id, function(link) | 106 getDocLink(event.target.id, link => |
109 { | 107 { |
110 openSharePopup(link); | 108 openSharePopup(link); |
111 }); | 109 }); |
112 } | 110 } |
113 | 111 |
114 function setLinks(id) | 112 function setLinks(id, ...args) |
115 { | 113 { |
116 var element = E(id); | 114 let element = E(id); |
117 if (!element) | 115 if (!element) |
| 116 return; |
| 117 |
| 118 let links = element.getElementsByTagName("a"); |
| 119 |
| 120 for (let i = 0; i < links.length; i++) |
118 { | 121 { |
119 return; | 122 if (typeof args[i] == "string") |
120 } | |
121 | |
122 var links = element.getElementsByTagName("a"); | |
123 | |
124 for (var i = 0; i < links.length; i++) | |
125 { | |
126 if (typeof arguments[i + 1] == "string") | |
127 { | 123 { |
128 links[i].href = arguments[i + 1]; | 124 links[i].href = args[i]; |
129 links[i].setAttribute("target", "_blank"); | 125 links[i].setAttribute("target", "_blank"); |
130 } | 126 } |
131 else if (typeof arguments[i + 1] == "function") | 127 else if (typeof args[i] == "function") |
132 { | 128 { |
133 links[i].href = "javascript:void(0);"; | 129 links[i].href = "javascript:void(0);"; |
134 links[i].addEventListener("click", arguments[i + 1], false); | 130 links[i].addEventListener("click", args[i], false); |
135 } | 131 } |
136 } | 132 } |
137 } | 133 } |
138 | 134 |
139 function openFilters() | 135 function openFilters() |
140 { | 136 { |
141 ext.backgroundPage.sendMessage({type: "app.open", what: "options"}); | 137 ext.backgroundPage.sendMessage({type: "app.open", what: "options"}); |
142 } | 138 } |
143 | 139 |
144 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 140 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
145 })(); | 141 } |
OLD | NEW |