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 | 25 // Load subscriptions for features |
26 var userAgent = ""; | 26 var featureSubscriptions = [ |
27 if (navigator.userAgent.indexOf("Gecko/") > -1) | 27 { |
28 userAgent = "firefox"; | 28 feature: "malware", |
29 else if (navigator.userAgent.indexOf("Chrome/") > -1) | 29 homepage: "http://malwaredomains.com/", |
30 userAgent = "chrome"; | 30 title: "Malware Domains", |
31 | 31 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" |
32 if (userAgent !== "") | 32 }, |
33 document.documentElement.className = userAgent; | 33 { |
34 | 34 feature: "social", |
35 var scripts = []; | 35 homepage: "https://www.fanboy.co.nz/", |
36 if (userAgent == "chrome") | 36 title: "Fanboy's Social Blocking List", |
37 { | 37 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
38 var backgroundPage = chrome.extension.getBackgroundPage(); | 38 }, |
39 var require = backgroundPage.require; | 39 { |
40 } | 40 feature: "tracking", |
41 else if (userAgent == "firefox") | 41 homepage: "https://easylist.adblockplus.org/", |
42 { | 42 title: "EasyPrivacy", |
43 scripts.push("utils.js"); | 43 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" |
44 } | 44 } |
45 scripts.push("i18n.js"); | 45 ]; |
46 | 46 |
47 function loadScripts() | 47 function onDOMLoaded() |
48 { | 48 { |
49 var scriptName = scripts.shift(); | 49 // Show warning if data corruption was detected |
50 var script = document.createElement("script"); | 50 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio
n) |
51 script.type = (userAgent == "firefox") ? "application/x-javascript;version=1
.7" : "text/javascript"; | 51 { |
52 script.addEventListener("load", (scripts.length == 0) ? onScriptsLoaded : lo
adScripts, false); | 52 E("dataCorruptionWarning").removeAttribute("hidden"); |
53 script.src = scriptName; | 53 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_filt
erstorage")); |
54 document.head.appendChild(script); | 54 } |
55 } | 55 |
56 | 56 // Set up URL |
57 function onScriptsLoaded() | 57 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter
ia"), openFilters); |
58 { | 58 |
59 if (userAgent == "chrome") | 59 shade = E("shade"); |
60 { | |
61 window.Utils = require("utils").Utils; | |
62 window.Prefs = require("prefs").Prefs; | |
63 } | |
64 | |
65 // Set up page title | |
66 var titleId = "firstRun_title_install"; | |
67 if (userAgent == "chrome" && backgroundPage.isFirstRun | |
68 || userAgent == "firefox" && UI.firstRunDone) | |
69 titleId = "firstRun_title_update"; | |
70 var pageTitle = i18n.getMessage(titleId); | |
71 document.title = document.getElementById("title-main").textContent = pageTit
le; | |
72 | |
73 shade = document.getElementById("shade"); | |
74 shade.addEventListener("mouseover", scrollPage, false); | 60 shade.addEventListener("mouseover", scrollPage, false); |
75 shade.addEventListener("mouseout", stopScroll, false); | 61 shade.addEventListener("mouseout", stopScroll, false); |
76 | 62 |
77 if (userAgent == "firefox") | 63 // Set up typo feature |
78 { | 64 if (require("typoBootstrap")) |
79 var typoSettings = document.createElement("script"); | 65 { |
80 typoSettings.type = "application/x-javascript;version=1.7"; | 66 var featureTypo = E("feature-typo"); |
81 typoSettings.src = "typoSettings.js"; | 67 featureTypo.removeAttribute("hidden"); |
82 document.head.appendChild(typoSettings); | 68 |
83 | |
84 var toggleTypo = document.getElementById("toggle-typo"); | |
85 updateToggleButton("typo", Prefs.correctTypos); | 69 updateToggleButton("typo", Prefs.correctTypos); |
86 toggleTypo.addEventListener("click", function(event) | 70 |
87 { | 71 var listener = function(name) |
88 TypoActions.setEnabled(!Prefs.correctTypos); | 72 { |
89 updateToggleButton("typo", Prefs.correctTypos); | 73 if (name == "correctTypos") |
| 74 updateToggleButton("typo", Prefs.correctTypos); |
| 75 } |
| 76 Prefs.addListener(listener); |
| 77 window.addEventListener("unload", function(event) |
| 78 { |
| 79 Prefs.removeListener(listener); |
90 }, false); | 80 }, false); |
91 } | 81 |
92 | 82 E("toggle-typo").addEventListener("click", toggleTypoCorrectionEnabled, fa
lse); |
93 var toggleMalware = document.getElementById("toggle-malware"); | 83 } |
94 updateToggleButton("malware", false); | 84 |
95 toggleMalware.addEventListener("click", function(event) | 85 // Set up feature buttons linked to subscriptions |
96 { | 86 featureSubscriptions.forEach(setToggleSubscriptionButton); |
97 // TODO | 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); |
98 }, false); | 102 }, false); |
99 | |
100 var toggleSocial = document.getElementById("toggle-social"); | |
101 updateToggleButton("social", false); | |
102 toggleSocial.addEventListener("click", function(event) | |
103 { | |
104 // TODO | |
105 }, false); | |
106 | |
107 var toggleTracking = document.getElementById("toggle-tracking"); | |
108 updateToggleButton("tracking", false); | |
109 toggleTracking.addEventListener("click", function(event) | |
110 { | |
111 // TODO | |
112 }, false); | |
113 | |
114 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads_criteria"),
openFilters); | |
115 | 103 |
116 window.addEventListener("resize", onWindowResize, false); | 104 window.addEventListener("resize", onWindowResize, false); |
117 document.addEventListener("scroll", onScroll, false); | 105 document.addEventListener("scroll", onScroll, false); |
118 | 106 |
119 onWindowResize(); | 107 onWindowResize(); |
120 | 108 |
121 initSocialLinks(null); | 109 initSocialLinks(null); |
122 } | 110 } |
123 | 111 |
124 function onScroll() | 112 function onScroll() |
125 { | 113 { |
126 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; |
127 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"; |
128 } | 116 } |
129 | 117 |
130 function onWindowResize() | 118 function onWindowResize() |
131 { | 119 { |
132 onScroll(); | 120 onScroll(); |
133 } | 121 } |
134 | 122 |
| 123 function toggleTypoCorrectionEnabled() |
| 124 { |
| 125 Prefs.correctTypos = !Prefs.correctTypos; |
| 126 } |
| 127 |
| 128 function isSubscriptionEnabled(featureSubscription) |
| 129 { |
| 130 return featureSubscription.url in FilterStorage.knownSubscriptions |
| 131 && !Subscription.fromURL(featureSubscription.url).disabled; |
| 132 } |
| 133 |
| 134 function setToggleSubscriptionButton(featureSubscription) |
| 135 { |
| 136 var feature = featureSubscription.feature; |
| 137 |
| 138 var element = E("toggle-" + feature); |
| 139 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription)); |
| 140 element.addEventListener("click", function(event) |
| 141 { |
| 142 var subscription = Subscription.fromURL(featureSubscription.url); |
| 143 if (isSubscriptionEnabled(featureSubscription)) |
| 144 FilterStorage.removeSubscription(subscription); |
| 145 else |
| 146 { |
| 147 subscription.disabled = false; |
| 148 subscription.title = featureSubscription.title; |
| 149 subscription.homepage = featureSubscription.homepage; |
| 150 FilterStorage.addSubscription(subscription); |
| 151 if (!subscription.lastDownload) |
| 152 Synchronizer.execute(subscription); |
| 153 } |
| 154 }, false); |
| 155 } |
| 156 |
135 function scrollPage() | 157 function scrollPage() |
136 { | 158 { |
137 if (scrollTimer) | 159 if (scrollTimer) |
138 stopScroll(); | 160 stopScroll(); |
139 | 161 |
140 scrollTimer = setInterval(function() | 162 scrollTimer = setInterval(function() |
141 { | 163 { |
142 window.scrollBy(0, 5); | 164 window.scrollBy(0, 5); |
143 }, 20); | 165 }, 20); |
144 } | 166 } |
145 | 167 |
146 function stopScroll() | 168 function stopScroll() |
147 { | 169 { |
148 clearTimeout(scrollTimer); | 170 clearTimeout(scrollTimer); |
149 scrollTimer = null; | 171 scrollTimer = null; |
150 } | 172 } |
151 | 173 |
152 function openSharePopup(url) | 174 function openSharePopup(url) |
153 { | 175 { |
154 var iframe = document.getElementById("share-popup"); | 176 var iframe = E("share-popup"); |
155 var glassPane = document.getElementById("glass-pane"); | 177 var glassPane = E("glass-pane"); |
156 var popupMessageReceived = false; | 178 var popupMessageReceived = false; |
157 | 179 |
158 var popupMessageListener = function(event) | 180 var popupMessageListener = function(event) |
159 { | 181 { |
160 var originFilter = Filter.fromText("||adblockplus.org^"); | 182 var originFilter = Filter.fromText("||adblockplus.org^"); |
161 if (!originFilter.matches(event.origin, "OTHER", null, null)) | 183 if (!originFilter.matches(event.origin, "OTHER", null, null)) |
162 return; | 184 return; |
163 | 185 |
164 var width = event.data.width; | 186 var width = event.data.width; |
165 var height = event.data.height; | 187 var height = event.data.height; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 220 |
199 iframe.src = url; | 221 iframe.src = url; |
200 glassPane.className = "visible"; | 222 glassPane.className = "visible"; |
201 } | 223 } |
202 | 224 |
203 function initSocialLinks(variant) | 225 function initSocialLinks(variant) |
204 { | 226 { |
205 var networks = ["twitter", "facebook", "gplus"]; | 227 var networks = ["twitter", "facebook", "gplus"]; |
206 networks.forEach(function(network) | 228 networks.forEach(function(network) |
207 { | 229 { |
208 var link = document.getElementById("share-" + network); | 230 var link = E("share-" + network); |
209 link.addEventListener("click", function(e) | 231 link.addEventListener("click", function(e) |
210 { | 232 { |
211 e.preventDefault(); | 233 e.preventDefault(); |
212 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); | 234 openSharePopup(Utils.getDocLink("share-" + network) + "&variant=" + vari
ant); |
213 }, false); | 235 }, false); |
214 }); | 236 }); |
215 } | 237 } |
216 | 238 |
217 function setLinks(id) | 239 function setLinks(id) |
218 { | 240 { |
219 var element = document.getElementById(id); | 241 var element = E(id); |
220 if (!element) | 242 if (!element) |
221 return; | 243 return; |
222 | 244 |
223 var links = element.getElementsByTagName("a"); | 245 var links = element.getElementsByTagName("a"); |
224 for (var i = 0; i < links.length; i++) | 246 for (var i = 0; i < links.length; i++) |
225 { | 247 { |
226 if (typeof arguments[i + 1] == "string") | 248 if (typeof arguments[i + 1] == "string") |
227 { | 249 { |
228 links[i].href = arguments[i + 1]; | 250 links[i].href = arguments[i + 1]; |
229 links[i].setAttribute("target", "_blank"); | 251 links[i].setAttribute("target", "_blank"); |
230 } | 252 } |
231 else if (typeof arguments[i + 1] == "function") | 253 else if (typeof arguments[i + 1] == "function") |
232 { | 254 { |
233 links[i].href = "javascript:void(0);"; | 255 links[i].href = "javascript:void(0);"; |
234 links[i].addEventListener("click", arguments[i + 1], false); | 256 links[i].addEventListener("click", arguments[i + 1], false); |
235 } | 257 } |
236 } | 258 } |
237 } | 259 } |
238 | 260 |
239 function getDocLink(page, anchor) | |
240 { | |
241 return Prefs.documentation_link | |
242 .replace(/%LINK%/g, page) | |
243 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor :
""); | |
244 } | |
245 | |
246 function openFilters() | 261 function openFilters() |
247 { | 262 { |
248 if (userAgent == "firefox") | 263 if (typeof UI != "undefined") |
249 UI.openFiltersDialog(); | 264 UI.openFiltersDialog(); |
250 else if (userAgent == "chrome") | 265 else |
251 { | 266 { |
252 backgroundPage.openOptions(); | 267 backgroundPage.openOptions(); |
253 } | 268 } |
254 } | 269 } |
255 | 270 |
256 function updateToggleButton(feature, isEnabled) | 271 function updateToggleButton(feature, isEnabled) |
257 { | 272 { |
258 var button = document.getElementById("toggle-" + feature); | 273 var button = E("toggle-" + feature); |
259 button.className = isEnabled ? "disable" : "enable"; | 274 button.className = isEnabled ? "disable" : "enable"; |
260 button.textContent = i18n.getMessage(isEnabled ? "firstRun_action_disable" :
"firstRun_action_enable"); | 275 button.textContent = i18n.getMessage(isEnabled ? "firstRun_action_disable" :
"firstRun_action_enable"); |
261 } | 276 } |
262 | 277 |
263 document.addEventListener("DOMContentLoaded", loadScripts, false); | 278 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
264 })(); | 279 })(); |
LEFT | RIGHT |