Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 (function() | 20 (function() |
21 { | 21 { |
22 var shade; | 22 var shade; |
23 var scrollTimer; | 23 var scrollTimer; |
24 | 24 |
25 // Determine platform | |
26 var userAgent = ""; | |
27 if (navigator.userAgent.indexOf("Gecko/") > -1) | |
28 userAgent = "firefox"; | |
29 else if (navigator.userAgent.indexOf("Chrome/") > -1) | |
30 userAgent = "chrome"; | |
31 | |
32 if (userAgent !== "") | |
33 document.documentElement.className = userAgent; | |
34 | |
35 // Load subscriptions for features | 25 // Load subscriptions for features |
36 var featureSubscriptions = [ | 26 var featureSubscriptions = [ |
37 { | 27 { |
38 feature: "malware", | 28 feature: "malware", |
29 homepage: "http://malwaredomains.com/", | |
39 title: "Malware Domains", | 30 title: "Malware Domains", |
40 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" | 31 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" |
Wladimir Palant
2013/05/27 14:10:37
Please add the homepage field as well - I noticed
Thomas Greiner
2013/05/27 16:39:16
Done.
| |
41 }, | 32 }, |
42 { | 33 { |
43 feature: "social", | 34 feature: "social", |
35 homepage: "https://www.fanboy.co.nz/", | |
44 title: "Fanboy's Social Blocking List", | 36 title: "Fanboy's Social Blocking List", |
45 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 37 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
46 }, | 38 }, |
47 { | 39 { |
48 feature: "tracking", | 40 feature: "tracking", |
41 homepage: "https://easylist.adblockplus.org/", | |
49 title: "EasyPrivacy", | 42 title: "EasyPrivacy", |
50 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" | 43 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" |
51 } | 44 } |
52 ]; | 45 ]; |
53 | 46 |
54 // Determine scripts to load | 47 function onDOMLoaded() |
55 var scripts = []; | 48 { |
56 if (userAgent == "chrome") | |
57 { | |
58 var backgroundPage = chrome.extension.getBackgroundPage(); | |
59 var require = backgroundPage.require; | |
60 } | |
61 else if (userAgent == "firefox") | |
62 { | |
63 scripts.push("utils.js"); | |
64 } | |
65 scripts.push("i18n.js"); | |
66 | |
67 function loadScripts() | |
68 { | |
69 var scriptName = scripts.shift(); | |
70 var script = document.createElement("script"); | |
71 script.type = (userAgent == "firefox") ? "application/x-javascript;version=1 .7" : "text/javascript"; | |
72 script.addEventListener("load", (scripts.length == 0) ? onScriptsLoaded : lo adScripts, false); | |
73 script.src = scriptName; | |
74 document.head.appendChild(script); | |
75 } | |
76 | |
77 function onScriptsLoaded() | |
78 { | |
79 if (userAgent == "chrome") | |
80 { | |
81 window.Synchronizer = require("synchronizer").Synchronizer; | |
82 window.Utils = require("utils").Utils; | |
83 window.Prefs = require("prefs").Prefs; | |
84 window.FilterStorage = require("filterStorage").FilterStorage; | |
85 | |
86 var subscriptionClasses = require("subscriptionClasses"); | |
87 window.Subscription = subscriptionClasses.Subscription; | |
88 window.DownloadableSubscription = subscriptionClasses.DownloadableSubscrip tion; | |
89 window.Filter = require("filterClasses").Filter; | |
90 } | |
91 | |
92 // Show warning if data corruption was detected | 49 // Show warning if data corruption was detected |
93 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio n) | 50 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio n) |
94 { | 51 { |
95 document.getElementById("dataCorruptionWarning").removeAttribute("hidden") ; | 52 E("dataCorruptionWarning").removeAttribute("hidden"); |
Wladimir Palant
2013/05/27 14:10:37
utils.js in Firefox defines a E("dataCorruptionWar
Thomas Greiner
2013/05/27 16:39:16
Done.
| |
96 setLinks("dataCorruptionWarning", getDocLink("knownIssuesChrome_filterstor age")); | 53 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_filt erstorage")); |
97 } | 54 } |
98 | 55 |
99 // Set up URLs | 56 // Set up URL |
100 var versionId; | 57 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter ia"), openFilters); |
101 var platformId; | 58 |
102 if (userAgent == "firefox") | 59 shade = E("shade"); |
103 { | |
104 versionId = Utils.addonVersion.match(/^[0-9\.]+/)[0].replace(/\./g, ""); | |
105 platformId = "firefox"; | |
106 } | |
107 else if (userAgent == "chrome") | |
108 { | |
109 versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join("" ); | |
110 platformId = "google-chrome"; | |
111 } | |
112 setLinks("title-changelog", "https://adblockplus.org/releases/adblock-plus-" + versionId + "-for-" + platformId + "-released"); | |
113 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads_criteria"), openFilters); | |
114 | |
115 shade = document.getElementById("shade"); | |
116 shade.addEventListener("mouseover", scrollPage, false); | 60 shade.addEventListener("mouseover", scrollPage, false); |
117 shade.addEventListener("mouseout", stopScroll, false); | 61 shade.addEventListener("mouseout", stopScroll, false); |
118 | 62 |
119 // Set up typo feature | 63 // Set up typo feature |
120 if (require("typoBootstrap")) | 64 if (require("typoBootstrap")) |
121 { | 65 { |
122 var toggleTypo = document.getElementById("toggle-typo"); | 66 var featureTypo = E("feature-typo"); |
67 featureTypo.removeAttribute("hidden"); | |
68 | |
123 updateToggleButton("typo", Prefs.correctTypos); | 69 updateToggleButton("typo", Prefs.correctTypos); |
124 Prefs.addListener(function(name) | 70 |
71 var listener = function(name) | |
125 { | 72 { |
126 if (name == "correctTypos") | 73 if (name == "correctTypos") |
127 updateToggleButton("typo", Prefs.correctTypos); | 74 updateToggleButton("typo", Prefs.correctTypos); |
128 }); | 75 } |
Wladimir Palant
2013/05/27 14:10:37
This listener needs to be removed on unload.
Thomas Greiner
2013/05/27 16:39:16
Done.
| |
129 toggleTypo.addEventListener("click", function(event) | 76 Prefs.addListener(listener); |
130 { | 77 window.addEventListener("unload", function(event) |
131 setTypoCorrectionEnabled(!Prefs.correctTypos); | 78 { |
Wladimir Palant
2013/05/27 14:10:37
How about Prefs.correctTypos = !Prefs.correctTypos
Thomas Greiner
2013/05/27 16:39:16
True! :)
Done.
| |
79 Prefs.removeListener(listener); | |
132 }, false); | 80 }, false); |
81 | |
82 E("toggle-typo").addEventListener("click", toggleTypoCorrectionEnabled, fa lse); | |
133 } | 83 } |
134 | 84 |
135 // Set up feature buttons linked to subscriptions | 85 // Set up feature buttons linked to subscriptions |
136 featureSubscriptions.forEach(setToggleSubscriptionButton); | 86 featureSubscriptions.forEach(setToggleSubscriptionButton); |
87 var filterListener = function(action) | |
88 { | |
89 if (/^subscription\.(added|removed|disabled)$/.test(action)) | |
90 { | |
91 for (var i = 0; i < featureSubscriptions.length; i++) | |
92 { | |
93 var featureSubscription = featureSubscriptions[i]; | |
94 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled( featureSubscription)); | |
95 } | |
96 } | |
97 } | |
98 FilterNotifier.addListener(filterListener); | |
99 window.addEventListener("unload", function(event) | |
100 { | |
101 FilterNotifier.removeListener(filterListener); | |
102 }, false); | |
137 | 103 |
138 window.addEventListener("resize", onWindowResize, false); | 104 window.addEventListener("resize", onWindowResize, false); |
139 document.addEventListener("scroll", onScroll, false); | 105 document.addEventListener("scroll", onScroll, false); |
140 | 106 |
141 onWindowResize(); | 107 onWindowResize(); |
142 | 108 |
143 initSocialLinks(null); | 109 initSocialLinks(null); |
144 } | 110 } |
145 | 111 |
146 function onScroll() | 112 function onScroll() |
147 { | 113 { |
148 var currentHeight = document.documentElement.scrollTop + document.body.scrol lTop + document.documentElement.clientHeight; | 114 var currentHeight = document.documentElement.scrollTop + document.body.scrol lTop + document.documentElement.clientHeight; |
149 shade.style.opacity = (document.documentElement.scrollHeight == currentHeigh t) ? "0.0" : "0.5"; | 115 shade.style.opacity = (document.documentElement.scrollHeight == currentHeigh t) ? "0.0" : "0.5"; |
150 } | 116 } |
151 | 117 |
152 function onWindowResize() | 118 function onWindowResize() |
153 { | 119 { |
154 onScroll(); | 120 onScroll(); |
155 } | 121 } |
156 | 122 |
157 function setTypoCorrectionEnabled(enable) | 123 function toggleTypoCorrectionEnabled() |
158 { | 124 { |
159 Prefs.correctTypos = enable; | 125 Prefs.correctTypos = !Prefs.correctTypos; |
160 } | 126 } |
161 | 127 |
162 function isSubscriptionEnabled(featureSubscription) | 128 function isSubscriptionEnabled(featureSubscription) |
163 { | 129 { |
164 return featureSubscription.url in FilterStorage.knownSubscriptions | 130 return featureSubscription.url in FilterStorage.knownSubscriptions |
165 && !Subscription.fromURL(featureSubscription.url).disabled; | 131 && !Subscription.fromURL(featureSubscription.url).disabled; |
166 } | 132 } |
167 | 133 |
168 function setToggleSubscriptionButton(featureSubscription) | 134 function setToggleSubscriptionButton(featureSubscription) |
169 { | 135 { |
170 var feature = featureSubscription.feature; | 136 var feature = featureSubscription.feature; |
171 | 137 |
172 var element = document.getElementById("toggle-" + feature); | 138 var element = E("toggle-" + feature); |
173 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription)); | 139 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription)); |
174 element.addEventListener("click", function(event) | 140 element.addEventListener("click", function(event) |
175 { | 141 { |
176 var subscription = Subscription.fromURL(featureSubscription.url); | 142 var subscription = Subscription.fromURL(featureSubscription.url); |
177 if (isSubscriptionEnabled(featureSubscription)) | 143 if (isSubscriptionEnabled(featureSubscription)) |
178 FilterStorage.removeSubscription(subscription); | 144 FilterStorage.removeSubscription(subscription); |
179 else | 145 else |
180 { | 146 { |
181 subscription.disabled = false; | 147 subscription.disabled = false; |
182 subscription.title = featureSubscription.title; | 148 subscription.title = featureSubscription.title; |
(...skipping 17 matching lines...) Expand all Loading... | |
200 } | 166 } |
201 | 167 |
202 function stopScroll() | 168 function stopScroll() |
203 { | 169 { |
204 clearTimeout(scrollTimer); | 170 clearTimeout(scrollTimer); |
205 scrollTimer = null; | 171 scrollTimer = null; |
206 } | 172 } |
207 | 173 |
208 function openSharePopup(url) | 174 function openSharePopup(url) |
209 { | 175 { |
210 var iframe = document.getElementById("share-popup"); | 176 var iframe = E("share-popup"); |
211 var glassPane = document.getElementById("glass-pane"); | 177 var glassPane = E("glass-pane"); |
212 var popupMessageReceived = false; | 178 var popupMessageReceived = false; |
213 | 179 |
214 var popupMessageListener = function(event) | 180 var popupMessageListener = function(event) |
215 { | 181 { |
216 var originFilter = Filter.fromText("||adblockplus.org^"); | 182 var originFilter = Filter.fromText("||adblockplus.org^"); |
217 if (!originFilter.matches(event.origin, "OTHER", null, null)) | 183 if (!originFilter.matches(event.origin, "OTHER", null, null)) |
218 return; | 184 return; |
219 | 185 |
220 var width = event.data.width; | 186 var width = event.data.width; |
221 var height = event.data.height; | 187 var height = event.data.height; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 220 |
255 iframe.src = url; | 221 iframe.src = url; |
256 glassPane.className = "visible"; | 222 glassPane.className = "visible"; |
257 } | 223 } |
258 | 224 |
259 function initSocialLinks(variant) | 225 function initSocialLinks(variant) |
260 { | 226 { |
261 var networks = ["twitter", "facebook", "gplus"]; | 227 var networks = ["twitter", "facebook", "gplus"]; |
262 networks.forEach(function(network) | 228 networks.forEach(function(network) |
263 { | 229 { |
264 var link = document.getElementById("share-" + network); | 230 var link = E("share-" + network); |
265 link.addEventListener("click", function(e) | 231 link.addEventListener("click", function(e) |
266 { | 232 { |
267 e.preventDefault(); | 233 e.preventDefault(); |
268 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); | 234 openSharePopup(Utils.getDocLink("share-" + network) + "&variant=" + vari ant); |
269 }, false); | 235 }, false); |
270 }); | 236 }); |
271 } | 237 } |
272 | 238 |
273 function setLinks(id) | 239 function setLinks(id) |
274 { | 240 { |
275 var element = document.getElementById(id); | 241 var element = E(id); |
276 if (!element) | 242 if (!element) |
277 return; | 243 return; |
278 | 244 |
279 var links = element.getElementsByTagName("a"); | 245 var links = element.getElementsByTagName("a"); |
280 for (var i = 0; i < links.length; i++) | 246 for (var i = 0; i < links.length; i++) |
281 { | 247 { |
282 if (typeof arguments[i + 1] == "string") | 248 if (typeof arguments[i + 1] == "string") |
283 { | 249 { |
284 links[i].href = arguments[i + 1]; | 250 links[i].href = arguments[i + 1]; |
285 links[i].setAttribute("target", "_blank"); | 251 links[i].setAttribute("target", "_blank"); |
286 } | 252 } |
287 else if (typeof arguments[i + 1] == "function") | 253 else if (typeof arguments[i + 1] == "function") |
288 { | 254 { |
289 links[i].href = "javascript:void(0);"; | 255 links[i].href = "javascript:void(0);"; |
290 links[i].addEventListener("click", arguments[i + 1], false); | 256 links[i].addEventListener("click", arguments[i + 1], false); |
291 } | 257 } |
292 } | 258 } |
293 } | |
294 | |
295 function getDocLink(page, anchor) | |
296 { | |
297 return Prefs.documentation_link | |
298 .replace(/%LINK%/g, page) | |
299 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : ""); | |
300 } | 259 } |
Wladimir Palant
2013/05/27 14:10:37
Comment not addressed (in addition to utils.js & C
Thomas Greiner
2013/05/27 16:39:16
Done.
| |
301 | 260 |
302 function openFilters() | 261 function openFilters() |
303 { | 262 { |
304 if (typeof UI != "undefined") | 263 if (typeof UI != "undefined") |
305 UI.openFiltersDialog(); | 264 UI.openFiltersDialog(); |
306 else | 265 else |
307 { | 266 { |
308 backgroundPage.openOptions(); | 267 backgroundPage.openOptions(); |
309 } | 268 } |
310 } | 269 } |
311 | 270 |
312 function updateToggleButton(feature, isEnabled) | 271 function updateToggleButton(feature, isEnabled) |
313 { | 272 { |
314 var button = document.getElementById("toggle-" + feature); | 273 var button = E("toggle-" + feature); |
315 button.className = isEnabled ? "disable" : "enable"; | 274 button.className = isEnabled ? "disable" : "enable"; |
316 button.textContent = i18n.getMessage(isEnabled ? "firstRun_action_disable" : "firstRun_action_enable"); | 275 button.textContent = i18n.getMessage(isEnabled ? "firstRun_action_disable" : "firstRun_action_enable"); |
317 } | 276 } |
318 | 277 |
319 document.addEventListener("DOMContentLoaded", loadScripts, false); | 278 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
320 })(); | 279 })(); |
LEFT | RIGHT |