Left: | ||
Right: |
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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 function init() | 18 "use strict"; |
19 | |
20 (function() | |
19 { | 21 { |
20 generateLinkText(E("changeDescription")); | 22 var shade; |
21 | 23 var scrollTimer; |
22 for each (let subscription in FilterStorage.subscriptions) | 24 |
23 { | 25 // Load subscriptions for features |
24 if (subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl && !subscription.disabled) | 26 var featureSubscriptions = [ |
25 { | 27 { |
26 E("listName").textContent = subscription.title; | 28 feature: "malware", |
27 | 29 homepage: "http://malwaredomains.com/", |
28 let link = E("listHomepage"); | 30 title: "Malware Domains", |
29 link.setAttribute("href", subscription.homepage); | 31 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" |
30 link.setAttribute("title", subscription.homepage); | 32 }, |
31 | 33 { |
32 E("listNameContainer").removeAttribute("hidden"); | 34 feature: "social", |
33 E("listNone").setAttribute("hidden", "true"); | 35 homepage: "https://www.fanboy.co.nz/", |
34 break; | 36 title: "Fanboy's Social Blocking List", |
35 } | 37 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
36 } | 38 }, |
37 | 39 { |
38 if (FilterStorage.subscriptions.some(function(s) s.url == Prefs.subscriptions_ exceptionsurl)) | 40 feature: "tracking", |
39 E("acceptableAds").removeAttribute("hidden"); | 41 homepage: "https://easylist.adblockplus.org/", |
40 } | 42 title: "EasyPrivacy", |
41 | 43 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" |
42 function generateLinkText(element) | 44 } |
43 { | 45 ]; |
44 let template = element.getAttribute("_textTemplate"); | 46 |
45 | 47 function onDOMLoaded() |
46 let [, beforeLink, linkText, afterLink] = /(.*)\[link\](.*)\[\/link\](.*)/.exe c(template) || [null, "", template, ""]; | 48 { |
47 while (element.firstChild && element.firstChild.nodeType != Node.ELEMENT_NODE) | 49 // Show warning if data corruption was detected |
48 element.removeChild(element.firstChild); | 50 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio n) |
49 while (element.lastChild && element.lastChild.nodeType != Node.ELEMENT_NODE) | 51 { |
50 element.removeChild(element.lastChild); | 52 E("dataCorruptionWarning").removeAttribute("hidden"); |
51 if (!element.firstChild) | 53 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_filt erstorage")); |
52 return; | 54 } |
53 | 55 |
54 element.firstChild.textContent = linkText; | 56 // Set up URL |
55 element.insertBefore(document.createTextNode(beforeLink), element.firstChild); | 57 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter ia"), openFilters); |
56 element.appendChild(document.createTextNode(afterLink)); | 58 |
57 } | 59 shade = E("shade"); |
58 | 60 shade.addEventListener("mouseover", scrollPage, false); |
59 function openFilters() | 61 shade.addEventListener("mouseout", stopScroll, false); |
60 { | 62 |
61 if (Utils.isFennec) | 63 // Set up typo feature |
62 { | 64 if (require("typoBootstrap")) |
63 let topWnd = window.QueryInterface(Ci.nsIInterfaceRequestor) | 65 { |
64 .getInterface(Ci.nsIWebNavigation) | 66 var featureTypo = E("feature-typo"); |
65 .QueryInterface(Ci.nsIDocShellTreeItem) | 67 featureTypo.removeAttribute("hidden"); |
66 .rootTreeItem | 68 |
67 .QueryInterface(Ci.nsIInterfaceRequestor) | 69 var toggleTypo = E("toggle-typo"); |
68 .getInterface(Ci.nsIDOMWindow); | 70 updateToggleButton("typo", Prefs.correctTypos); |
69 if (topWnd.wrappedJSObject) | 71 |
70 topWnd = topWnd.wrappedJSObject; | 72 var listener = function(name) |
71 | 73 { |
72 // window.close() closes the entire window (bug 642604), make sure to close | 74 if (name == "correctTypos") |
73 // only a single tab instead. | 75 updateToggleButton("typo", Prefs.correctTypos); |
74 if ("BrowserUI" in topWnd) | 76 } |
75 { | 77 Prefs.addListener(listener); |
76 topWnd.BrowserUI.showPanel("addons-container"); | 78 window.addEventListener("unload", function(event) |
77 function showOptions() | 79 { |
78 { | 80 Prefs.removeListener(listener); |
79 if (!topWnd.ExtensionsView.getElementForAddon(Utils.addonID)) | 81 }, false); |
80 Utils.runAsync(showOptions); | 82 |
81 else | 83 toggleTypo.addEventListener("click", function(event) |
82 topWnd.ExtensionsView.showOptions(Utils.addonID); | 84 { |
83 } | 85 toggleTypoCorrectionEnabled(); |
84 showOptions(); | 86 }, false); |
Wladimir Palant
2013/05/28 13:39:01
If you want a function then please don't wrap it i
| |
85 } | 87 } |
86 } | 88 |
87 else | 89 // Set up feature buttons linked to subscriptions |
88 UI.openFiltersDialog(); | 90 featureSubscriptions.forEach(setToggleSubscriptionButton); |
89 } | 91 var filterListener = function(action) |
92 { | |
93 for (var i = 0; i < featureSubscriptions.length; i++) | |
94 { | |
95 if (/^(filter|subscription)\.(added|removed|disabled)$/.test(action)) | |
Wladimir Palant
2013/05/28 13:39:01
This regexp should be: /^subscription\.(added|remo
| |
96 { | |
97 var featureSubscription = featureSubscriptions[i]; | |
98 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled( featureSubscription)); | |
99 } | |
100 } | |
101 } | |
102 FilterNotifier.addListener(filterListener); | |
103 window.addEventListener("unload", function(event) | |
104 { | |
105 FilterNotifier.removeListener(filterListener); | |
106 }, false); | |
107 | |
108 window.addEventListener("resize", onWindowResize, false); | |
109 document.addEventListener("scroll", onScroll, false); | |
110 | |
111 onWindowResize(); | |
112 | |
113 initSocialLinks(null); | |
114 } | |
115 | |
116 function onScroll() | |
117 { | |
118 var currentHeight = document.documentElement.scrollTop + document.body.scrol lTop + document.documentElement.clientHeight; | |
119 shade.style.opacity = (document.documentElement.scrollHeight == currentHeigh t) ? "0.0" : "0.5"; | |
120 } | |
121 | |
122 function onWindowResize() | |
123 { | |
124 onScroll(); | |
125 } | |
126 | |
127 function toggleTypoCorrectionEnabled() | |
128 { | |
129 Prefs.correctTypos = !Prefs.correctTypos; | |
130 } | |
131 | |
132 function isSubscriptionEnabled(featureSubscription) | |
133 { | |
134 return featureSubscription.url in FilterStorage.knownSubscriptions | |
135 && !Subscription.fromURL(featureSubscription.url).disabled; | |
136 } | |
137 | |
138 function setToggleSubscriptionButton(featureSubscription) | |
139 { | |
140 var feature = featureSubscription.feature; | |
141 | |
142 var element = E("toggle-" + feature); | |
143 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription)); | |
144 element.addEventListener("click", function(event) | |
145 { | |
146 var subscription = Subscription.fromURL(featureSubscription.url); | |
147 if (isSubscriptionEnabled(featureSubscription)) | |
148 FilterStorage.removeSubscription(subscription); | |
149 else | |
150 { | |
151 subscription.disabled = false; | |
152 subscription.title = featureSubscription.title; | |
153 subscription.homepage = featureSubscription.homepage; | |
154 FilterStorage.addSubscription(subscription); | |
155 if (!subscription.lastDownload) | |
156 Synchronizer.execute(subscription); | |
157 } | |
158 }, false); | |
159 } | |
160 | |
161 function scrollPage() | |
162 { | |
163 if (scrollTimer) | |
164 stopScroll(); | |
165 | |
166 scrollTimer = setInterval(function() | |
167 { | |
168 window.scrollBy(0, 5); | |
169 }, 20); | |
170 } | |
171 | |
172 function stopScroll() | |
173 { | |
174 clearTimeout(scrollTimer); | |
175 scrollTimer = null; | |
176 } | |
177 | |
178 function openSharePopup(url) | |
179 { | |
180 var iframe = E("share-popup"); | |
181 var glassPane = E("glass-pane"); | |
182 var popupMessageReceived = false; | |
183 | |
184 var popupMessageListener = function(event) | |
185 { | |
186 var originFilter = Filter.fromText("||adblockplus.org^"); | |
187 if (!originFilter.matches(event.origin, "OTHER", null, null)) | |
188 return; | |
189 | |
190 var width = event.data.width; | |
191 var height = event.data.height; | |
192 iframe.width = width; | |
193 iframe.height = height; | |
194 iframe.style.marginTop = -height/2 + "px"; | |
195 iframe.style.marginLeft = -width/2 + "px"; | |
196 popupMessageReceived = true; | |
197 window.removeEventListener("message", popupMessageListener); | |
198 }; | |
199 // Firefox requires last parameter to be true to be triggered by unprivilege d pages | |
200 window.addEventListener("message", popupMessageListener, false, true); | |
201 | |
202 var popupLoadListener = function() | |
203 { | |
204 if (popupMessageReceived) | |
205 { | |
206 iframe.className = "visible"; | |
207 | |
208 var popupCloseListener = function() | |
209 { | |
210 iframe.className = glassPane.className = ""; | |
211 document.removeEventListener("click", popupCloseListener); | |
212 }; | |
213 document.addEventListener("click", popupCloseListener, false); | |
214 } | |
215 else | |
216 { | |
217 glassPane.className = ""; | |
218 window.removeEventListener("message", popupMessageListener); | |
219 } | |
220 | |
221 iframe.removeEventListener("load", popupLoadListener); | |
222 }; | |
223 iframe.addEventListener("load", popupLoadListener, false); | |
224 | |
225 iframe.src = url; | |
226 glassPane.className = "visible"; | |
227 } | |
228 | |
229 function initSocialLinks(variant) | |
230 { | |
231 var networks = ["twitter", "facebook", "gplus"]; | |
232 networks.forEach(function(network) | |
233 { | |
234 var link = E("share-" + network); | |
235 link.addEventListener("click", function(e) | |
236 { | |
237 e.preventDefault(); | |
238 openSharePopup(Utils.getDocLink("share-" + network) + "&variant=" + vari ant); | |
239 }, false); | |
240 }); | |
241 } | |
242 | |
243 function setLinks(id) | |
244 { | |
245 var element = E(id); | |
246 if (!element) | |
247 return; | |
248 | |
249 var links = element.getElementsByTagName("a"); | |
250 for (var i = 0; i < links.length; i++) | |
251 { | |
252 if (typeof arguments[i + 1] == "string") | |
253 { | |
254 links[i].href = arguments[i + 1]; | |
255 links[i].setAttribute("target", "_blank"); | |
256 } | |
257 else if (typeof arguments[i + 1] == "function") | |
258 { | |
259 links[i].href = "javascript:void(0);"; | |
260 links[i].addEventListener("click", arguments[i + 1], false); | |
261 } | |
262 } | |
263 } | |
264 | |
265 function openFilters() | |
266 { | |
267 if (typeof UI != "undefined") | |
268 UI.openFiltersDialog(); | |
269 else | |
270 { | |
271 backgroundPage.openOptions(); | |
272 } | |
273 } | |
274 | |
275 function updateToggleButton(feature, isEnabled) | |
276 { | |
277 var button = E("toggle-" + feature); | |
278 button.className = isEnabled ? "disable" : "enable"; | |
279 button.textContent = i18n.getMessage(isEnabled ? "firstRun_action_disable" : "firstRun_action_enable"); | |
280 } | |
281 | |
282 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | |
283 })(); | |
OLD | NEW |