OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 23 matching lines...) Expand all Loading... |
34 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 34 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
35 }, | 35 }, |
36 { | 36 { |
37 feature: "tracking", | 37 feature: "tracking", |
38 homepage: "https://easylist.adblockplus.org/", | 38 homepage: "https://easylist.adblockplus.org/", |
39 title: "EasyPrivacy", | 39 title: "EasyPrivacy", |
40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" | 40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" |
41 } | 41 } |
42 ]; | 42 ]; |
43 | 43 |
| 44 function getDocLink(link, callback) |
| 45 { |
| 46 ext.backgroundPage.sendMessage({ |
| 47 type: "app.get", |
| 48 what: "doclink", |
| 49 link: link |
| 50 }, callback); |
| 51 } |
| 52 |
44 function onDOMLoaded() | 53 function onDOMLoaded() |
45 { | 54 { |
46 // Set up URLs | 55 // Set up URLs |
47 var donateLink = E("donate"); | 56 getDocLink("donate", function(link) |
48 donateLink.href = Utils.getDocLink("donate"); | 57 { |
| 58 E("donate").href = link; |
| 59 }); |
49 | 60 |
50 var contributors = E("contributors"); | 61 getDocLink("contributors", function(link) |
51 contributors.href = Utils.getDocLink("contributors"); | 62 { |
| 63 E("contributors").href = link; |
| 64 }); |
52 | 65 |
53 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter
ia"), openFilters); | 66 getDocLink("acceptable_ads_criteria", function(link) |
54 setLinks("share-headline", Utils.getDocLink("contribute")); | 67 { |
| 68 setLinks("acceptableAdsExplanation", link, openFilters); |
| 69 }); |
55 | 70 |
56 if (typeof backgroundPage != "undefined") | 71 getDocLink("contribute", function(link) |
| 72 { |
| 73 setLinks("share-headline", link); |
| 74 }); |
| 75 |
| 76 ext.backgroundPage.sendMessage({ |
| 77 type: "app.get", |
| 78 what: "issues" |
| 79 }, function(issues) |
57 { | 80 { |
58 // Show warning if data corruption was detected | 81 // Show warning if data corruption was detected |
59 if (backgroundPage.seenDataCorruption) | 82 if (issues.seenDataCorruption) |
60 { | 83 { |
61 E("dataCorruptionWarning").removeAttribute("hidden"); | 84 E("dataCorruptionWarning").removeAttribute("hidden"); |
62 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_fi
lterstorage")); | 85 getDocLink("knownIssuesChrome_filterstorage", function(link) |
| 86 { |
| 87 setLinks("dataCorruptionWarning", link); |
| 88 }); |
63 } | 89 } |
64 | 90 |
65 // Show warning if filterlists settings were reinitialized | 91 // Show warning if filterlists settings were reinitialized |
66 if (backgroundPage.filterlistsReinitialized) | 92 if (issues.filterlistsReinitialized) |
67 { | 93 { |
68 E("filterlistsReinitializedWarning").removeAttribute("hidden"); | 94 E("filterlistsReinitializedWarning").removeAttribute("hidden"); |
69 setLinks("filterlistsReinitializedWarning", openFilters); | 95 setLinks("filterlistsReinitializedWarning", openFilters); |
70 } | 96 } |
71 } | |
72 | 97 |
73 // Show warning if Safari version isn't supported | 98 if (issues.legacySafariVersion) |
74 var info = require("info"); | 99 E("legacySafariWarning").removeAttribute("hidden"); |
75 if (info.platform == "safari" && ( | 100 }); |
76 Services.vc.compare(info.platformVersion, "6.0") < 0 || // beforeload br
eaks websites in Safari 5 | |
77 Services.vc.compare(info.platformVersion, "6.1") == 0 || // extensions ar
e broken in 6.1 and 7.0 | |
78 Services.vc.compare(info.platformVersion, "7.0") == 0 | |
79 )) | |
80 E("legacySafariWarning").removeAttribute("hidden"); | |
81 | 101 |
82 // Set up feature buttons linked to subscriptions | 102 // Set up feature buttons linked to subscriptions |
83 featureSubscriptions.forEach(setToggleSubscriptionButton); | 103 featureSubscriptions.forEach(initToggleSubscriptionButton); |
84 var filterListener = function(action) | 104 updateToggleButtons(); |
| 105 updateSocialLinks(); |
| 106 |
| 107 ext.onMessage.addListener(function(message) |
85 { | 108 { |
86 if (/^subscription\.(added|removed|disabled)$/.test(action)) | 109 if (message.type == "subscriptions.listen") |
87 { | 110 { |
88 for (var i = 0; i < featureSubscriptions.length; i++) | 111 updateToggleButtons(); |
89 { | 112 updateSocialLinks(); |
90 var featureSubscription = featureSubscriptions[i]; | |
91 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled(
featureSubscription)); | |
92 } | |
93 } | 113 } |
94 } | 114 }); |
95 FilterNotifier.addListener(filterListener); | 115 ext.backgroundPage.sendMessage({ |
96 window.addEventListener("unload", function(event) | 116 type: "subscriptions.listen", |
97 { | 117 filter: ["added", "removed", "disabled"] |
98 FilterNotifier.removeListener(filterListener); | 118 }); |
99 }, false); | |
100 | |
101 initSocialLinks(); | |
102 } | 119 } |
103 | 120 |
104 function isSubscriptionEnabled(featureSubscription) | 121 function initToggleSubscriptionButton(featureSubscription) |
105 { | |
106 return featureSubscription.url in FilterStorage.knownSubscriptions | |
107 && !Subscription.fromURL(featureSubscription.url).disabled; | |
108 } | |
109 | |
110 function setToggleSubscriptionButton(featureSubscription) | |
111 { | 122 { |
112 var feature = featureSubscription.feature; | 123 var feature = featureSubscription.feature; |
113 | 124 |
114 var element = E("toggle-" + feature); | 125 var element = E("toggle-" + feature); |
115 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription)); | |
116 element.addEventListener("click", function(event) | 126 element.addEventListener("click", function(event) |
117 { | 127 { |
118 var subscription = Subscription.fromURL(featureSubscription.url); | 128 ext.backgroundPage.sendMessage({ |
119 if (isSubscriptionEnabled(featureSubscription)) | 129 type: "subscriptions.toggle", |
120 FilterStorage.removeSubscription(subscription); | 130 url: featureSubscription.url, |
121 else | 131 title: featureSubscription.title, |
122 { | 132 homepage: featureSubscription.homepage |
123 subscription.disabled = false; | 133 }); |
124 subscription.title = featureSubscription.title; | |
125 subscription.homepage = featureSubscription.homepage; | |
126 FilterStorage.addSubscription(subscription); | |
127 if (!subscription.lastDownload) | |
128 Synchronizer.execute(subscription); | |
129 } | |
130 }, false); | 134 }, false); |
131 } | 135 } |
132 | 136 |
133 function openSharePopup(url) | 137 function openSharePopup(url) |
134 { | 138 { |
135 var iframe = E("share-popup"); | 139 var iframe = E("share-popup"); |
136 var glassPane = E("glass-pane"); | 140 var glassPane = E("glass-pane"); |
137 var popupMessageReceived = false; | 141 var popupMessageReceived = false; |
138 | 142 |
139 var popupMessageListener = function(event) | 143 var popupMessageListener = function(event) |
140 { | 144 { |
141 var originFilter = Filter.fromText("||adblockplus.org^"); | 145 if (!/[.\/]adblockplus\.org$/.test(event.origin)) |
142 if (!originFilter.matches(event.origin, "OTHER", null, null)) | |
143 return; | 146 return; |
144 | 147 |
145 var width = event.data.width; | 148 var width = event.data.width; |
146 var height = event.data.height; | 149 var height = event.data.height; |
147 iframe.width = width; | 150 iframe.width = width; |
148 iframe.height = height; | 151 iframe.height = height; |
149 iframe.style.marginTop = -height/2 + "px"; | 152 iframe.style.marginTop = -height/2 + "px"; |
150 iframe.style.marginLeft = -width/2 + "px"; | 153 iframe.style.marginLeft = -width/2 + "px"; |
151 popupMessageReceived = true; | 154 popupMessageReceived = true; |
152 window.removeEventListener("message", popupMessageListener); | 155 window.removeEventListener("message", popupMessageListener); |
(...skipping 21 matching lines...) Expand all Loading... |
174 } | 177 } |
175 | 178 |
176 iframe.removeEventListener("load", popupLoadListener); | 179 iframe.removeEventListener("load", popupLoadListener); |
177 }; | 180 }; |
178 iframe.addEventListener("load", popupLoadListener, false); | 181 iframe.addEventListener("load", popupLoadListener, false); |
179 | 182 |
180 iframe.src = url; | 183 iframe.src = url; |
181 glassPane.className = "visible"; | 184 glassPane.className = "visible"; |
182 } | 185 } |
183 | 186 |
184 function initSocialLinks() | 187 function updateSocialLinks() |
185 { | 188 { |
186 var networks = ["twitter", "facebook", "gplus"]; | 189 var networks = ["twitter", "facebook", "gplus"]; |
187 networks.forEach(function(network) | 190 networks.forEach(function(network) |
188 { | 191 { |
189 var link = E("share-" + network); | 192 var link = E("share-" + network); |
190 link.addEventListener("click", onSocialLinkClick, false); | 193 var message = { |
| 194 type: "filters.blocked", |
| 195 url: link.getAttribute("data-script"), |
| 196 requestType: "SCRIPT", |
| 197 docDomain: "adblockplus.org", |
| 198 thirdParty: true |
| 199 }; |
| 200 ext.backgroundPage.sendMessage(message, function(blocked) |
| 201 { |
| 202 // Don't open the share page if the sharing script would be blocked |
| 203 if (blocked) |
| 204 link.removeEventListener("click", onSocialLinkClick, false); |
| 205 else |
| 206 link.addEventListener("click", onSocialLinkClick, false); |
| 207 }); |
191 }); | 208 }); |
192 } | 209 } |
193 | 210 |
194 function onSocialLinkClick(event) | 211 function onSocialLinkClick(event) |
195 { | 212 { |
196 // Don't open the share page if the sharing script would be blocked | 213 event.preventDefault(); |
197 var filter = defaultMatcher.matchesAny(event.target.getAttribute("data-scrip
t"), "SCRIPT", "adblockplus.org", true); | 214 |
198 if (!(filter instanceof BlockingFilter)) | 215 getDocLink(event.target.id, function(link) |
199 { | 216 { |
200 event.preventDefault(); | 217 openSharePopup(link); |
201 openSharePopup(Utils.getDocLink(event.target.id)); | 218 }); |
202 } | |
203 } | 219 } |
204 | 220 |
205 function setLinks(id) | 221 function setLinks(id) |
206 { | 222 { |
207 var element = E(id); | 223 var element = E(id); |
208 if (!element) | 224 if (!element) |
209 { | 225 { |
210 return; | 226 return; |
211 } | 227 } |
212 | 228 |
213 var links = element.getElementsByTagName("a"); | 229 var links = element.getElementsByTagName("a"); |
214 | 230 |
215 for (var i = 0; i < links.length; i++) | 231 for (var i = 0; i < links.length; i++) |
216 { | 232 { |
217 if (typeof arguments[i + 1] == "string") | 233 if (typeof arguments[i + 1] == "string") |
218 { | 234 { |
219 links[i].href = arguments[i + 1]; | 235 links[i].href = arguments[i + 1]; |
220 links[i].setAttribute("target", "_blank"); | 236 links[i].setAttribute("target", "_blank"); |
221 } | 237 } |
222 else if (typeof arguments[i + 1] == "function") | 238 else if (typeof arguments[i + 1] == "function") |
223 { | 239 { |
224 links[i].href = "javascript:void(0);"; | 240 links[i].href = "javascript:void(0);"; |
225 links[i].addEventListener("click", arguments[i + 1], false); | 241 links[i].addEventListener("click", arguments[i + 1], false); |
226 } | 242 } |
227 } | 243 } |
228 } | 244 } |
229 | 245 |
230 function openFilters() | 246 function openFilters() |
231 { | 247 { |
232 if (typeof UI != "undefined") | 248 ext.backgroundPage.sendMessage({type: "app.open", what: "options"}); |
233 UI.openFiltersDialog(); | 249 } |
234 else | 250 |
| 251 function updateToggleButtons() |
| 252 { |
| 253 ext.backgroundPage.sendMessage({ |
| 254 type: "subscriptions.get", |
| 255 downloadable: true, |
| 256 ignoreDisabled: true |
| 257 }, function(subscriptions) |
235 { | 258 { |
236 backgroundPage.openOptions(); | 259 for (var i = 0; i < featureSubscriptions.length; i++) |
237 } | 260 { |
| 261 var featureSubscription = featureSubscriptions[i]; |
| 262 updateToggleButton(featureSubscription.feature, subscriptions.indexOf(fe
atureSubscription.url) >= 0); |
| 263 } |
| 264 }); |
238 } | 265 } |
239 | 266 |
240 function updateToggleButton(feature, isEnabled) | 267 function updateToggleButton(feature, isEnabled) |
241 { | 268 { |
242 var button = E("toggle-" + feature); | 269 var button = E("toggle-" + feature); |
243 if (isEnabled) | 270 if (isEnabled) |
244 button.classList.remove("off"); | 271 button.classList.remove("off"); |
245 else | 272 else |
246 button.classList.add("off"); | 273 button.classList.add("off"); |
247 } | 274 } |
248 | 275 |
249 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 276 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
250 })(); | 277 })(); |
OLD | NEW |