| 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; | |
| 23 var scrollTimer; | |
| 24 | |
| 25 // Load subscriptions for features | 22 // Load subscriptions for features |
| 26 var featureSubscriptions = [ | 23 var featureSubscriptions = [ |
| 27 { | 24 { |
| 28 feature: "malware", | 25 feature: "malware", |
| 29 homepage: "http://malwaredomains.com/", | 26 homepage: "http://malwaredomains.com/", |
| 30 title: "Malware Domains", | 27 title: "Malware Domains", |
| 31 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" | 28 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" |
| 32 }, | 29 }, |
| 33 { | 30 { |
| 34 feature: "social", | 31 feature: "social", |
| 35 homepage: "https://www.fanboy.co.nz/", | 32 homepage: "https://www.fanboy.co.nz/", |
| 36 title: "Fanboy's Social Blocking List", | 33 title: "Fanboy's Social Blocking List", |
| 37 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 34 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
| 38 }, | 35 }, |
| 39 { | 36 { |
| 40 feature: "tracking", | 37 feature: "tracking", |
| 41 homepage: "https://easylist.adblockplus.org/", | 38 homepage: "https://easylist.adblockplus.org/", |
| 42 title: "EasyPrivacy", | 39 title: "EasyPrivacy", |
| 43 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" | 40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" |
| 44 } | 41 } |
| 45 ]; | 42 ]; |
| 46 | 43 |
| 47 function onDOMLoaded() | 44 function onDOMLoaded() |
| 48 { | 45 { |
| 46 var locale = require("utils").Utils.appLocale; |
| 47 document.documentElement.setAttribute("lang", locale); |
| 48 |
| 49 // Set up URLs |
| 50 var donateLink = E("donate"); |
| 51 donateLink.href = Utils.getDocLink("donate"); |
| 52 |
| 53 var contributors = E("contributors"); |
| 54 contributors.href = Utils.getDocLink("contributors"); |
| 55 |
| 56 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter
ia"), openFilters); |
| 57 setLinks("share-headline", Utils.getDocLink("contribute")); |
| 58 |
| 49 // Show warning if data corruption was detected | 59 // Show warning if data corruption was detected |
| 50 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio
n) | 60 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio
n) |
| 51 { | 61 { |
| 52 E("dataCorruptionWarning").removeAttribute("hidden"); | 62 E("dataCorruptionWarning").removeAttribute("hidden"); |
| 53 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_filt
erstorage")); | 63 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_filt
erstorage")); |
| 54 } | 64 } |
| 55 | 65 |
| 56 // Show warning if Safari < 6 | 66 // Show warning if Safari < 6 |
| 57 var info = require("info"); | 67 var info = require("info"); |
| 58 if (info.platform == "safari" && Services.vc.compare(info.platformVersion, "
6.0") < 0) | 68 if (info.platform == "safari" && Services.vc.compare(info.platformVersion, "
6.0") < 0) |
| 59 E("legacySafariWarning").removeAttribute("hidden"); | 69 E("legacySafariWarning").removeAttribute("hidden"); |
| 60 | |
| 61 // Set up URL | |
| 62 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter
ia"), openFilters); | |
| 63 | |
| 64 shade = E("shade"); | |
| 65 shade.addEventListener("mouseover", scrollPage, false); | |
| 66 shade.addEventListener("mouseout", stopScroll, false); | |
| 67 | 70 |
| 68 // Set up feature buttons linked to subscriptions | 71 // Set up feature buttons linked to subscriptions |
| 69 featureSubscriptions.forEach(setToggleSubscriptionButton); | 72 featureSubscriptions.forEach(setToggleSubscriptionButton); |
| 70 var filterListener = function(action) | 73 var filterListener = function(action) |
| 71 { | 74 { |
| 72 if (/^subscription\.(added|removed|disabled)$/.test(action)) | 75 if (/^subscription\.(added|removed|disabled)$/.test(action)) |
| 73 { | 76 { |
| 74 for (var i = 0; i < featureSubscriptions.length; i++) | 77 for (var i = 0; i < featureSubscriptions.length; i++) |
| 75 { | 78 { |
| 76 var featureSubscription = featureSubscriptions[i]; | 79 var featureSubscription = featureSubscriptions[i]; |
| 77 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled(
featureSubscription)); | 80 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled(
featureSubscription)); |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 } | 83 } |
| 81 FilterNotifier.addListener(filterListener); | 84 FilterNotifier.addListener(filterListener); |
| 82 window.addEventListener("unload", function(event) | 85 window.addEventListener("unload", function(event) |
| 83 { | 86 { |
| 84 FilterNotifier.removeListener(filterListener); | 87 FilterNotifier.removeListener(filterListener); |
| 85 }, false); | 88 }, false); |
| 86 | 89 |
| 87 window.addEventListener("resize", onWindowResize, false); | 90 // You can click activate-feature or one of the icons to toggle the features
area |
| 88 document.addEventListener("scroll", onScroll, false); | 91 E("activate-features").addEventListener("click", toggleFeature, false); |
| 89 | 92 E("can-do-more-overview").addEventListener("click", toggleFeature, false); |
| 90 onWindowResize(); | |
| 91 | 93 |
| 92 initSocialLinks(); | 94 initSocialLinks(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 function onScroll() | 97 function toggleFeature() |
| 96 { | 98 { |
| 97 var currentHeight = document.documentElement.scrollTop + document.body.scrol
lTop + document.documentElement.clientHeight; | 99 E("can-do-more").classList.toggle("expanded"); |
| 98 shade.style.opacity = (document.documentElement.scrollHeight == currentHeigh
t) ? "0.0" : "0.5"; | |
| 99 } | |
| 100 | |
| 101 function onWindowResize() | |
| 102 { | |
| 103 onScroll(); | |
| 104 } | |
| 105 | |
| 106 function toggleTypoCorrectionEnabled() | |
| 107 { | |
| 108 Prefs.correctTypos = !Prefs.correctTypos; | |
| 109 } | 100 } |
| 110 | 101 |
| 111 function isSubscriptionEnabled(featureSubscription) | 102 function isSubscriptionEnabled(featureSubscription) |
| 112 { | 103 { |
| 113 return featureSubscription.url in FilterStorage.knownSubscriptions | 104 return featureSubscription.url in FilterStorage.knownSubscriptions |
| 114 && !Subscription.fromURL(featureSubscription.url).disabled; | 105 && !Subscription.fromURL(featureSubscription.url).disabled; |
| 115 } | 106 } |
| 116 | 107 |
| 117 function setToggleSubscriptionButton(featureSubscription) | 108 function setToggleSubscriptionButton(featureSubscription) |
| 118 { | 109 { |
| 119 var feature = featureSubscription.feature; | 110 var feature = featureSubscription.feature; |
| 120 | 111 |
| 121 var element = E("toggle-" + feature); | 112 var element = E("toggle-" + feature); |
| 122 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription)); | 113 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription)); |
| 123 element.addEventListener("click", function(event) | 114 element.addEventListener("click", function(event) |
| 124 { | 115 { |
| 125 var subscription = Subscription.fromURL(featureSubscription.url); | 116 var subscription = Subscription.fromURL(featureSubscription.url); |
| 126 if (isSubscriptionEnabled(featureSubscription)) | 117 if (isSubscriptionEnabled(featureSubscription)) |
| 127 FilterStorage.removeSubscription(subscription); | 118 FilterStorage.removeSubscription(subscription); |
| 128 else | 119 else |
| 129 { | 120 { |
| 130 subscription.disabled = false; | 121 subscription.disabled = false; |
| 131 subscription.title = featureSubscription.title; | 122 subscription.title = featureSubscription.title; |
| 132 subscription.homepage = featureSubscription.homepage; | 123 subscription.homepage = featureSubscription.homepage; |
| 133 FilterStorage.addSubscription(subscription); | 124 FilterStorage.addSubscription(subscription); |
| 134 if (!subscription.lastDownload) | 125 if (!subscription.lastDownload) |
| 135 Synchronizer.execute(subscription); | 126 Synchronizer.execute(subscription); |
| 136 } | 127 } |
| 137 }, false); | 128 }, false); |
| 138 } | |
| 139 | |
| 140 function scrollPage() | |
| 141 { | |
| 142 if (scrollTimer) | |
| 143 stopScroll(); | |
| 144 | |
| 145 scrollTimer = setInterval(function() | |
| 146 { | |
| 147 window.scrollBy(0, 5); | |
| 148 }, 20); | |
| 149 } | |
| 150 | |
| 151 function stopScroll() | |
| 152 { | |
| 153 clearTimeout(scrollTimer); | |
| 154 scrollTimer = null; | |
| 155 } | 129 } |
| 156 | 130 |
| 157 function openSharePopup(url) | 131 function openSharePopup(url) |
| 158 { | 132 { |
| 159 var iframe = E("share-popup"); | 133 var iframe = E("share-popup"); |
| 160 var glassPane = E("glass-pane"); | 134 var glassPane = E("glass-pane"); |
| 161 var popupMessageReceived = false; | 135 var popupMessageReceived = false; |
| 162 | 136 |
| 163 var popupMessageListener = function(event) | 137 var popupMessageListener = function(event) |
| 164 { | 138 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 { | 197 { |
| 224 event.preventDefault(); | 198 event.preventDefault(); |
| 225 openSharePopup(Utils.getDocLink(event.target.id)); | 199 openSharePopup(Utils.getDocLink(event.target.id)); |
| 226 } | 200 } |
| 227 } | 201 } |
| 228 | 202 |
| 229 function setLinks(id) | 203 function setLinks(id) |
| 230 { | 204 { |
| 231 var element = E(id); | 205 var element = E(id); |
| 232 if (!element) | 206 if (!element) |
| 207 { |
| 233 return; | 208 return; |
| 209 } |
| 234 | 210 |
| 235 var links = element.getElementsByTagName("a"); | 211 var links = element.getElementsByTagName("a"); |
| 212 |
| 236 for (var i = 0; i < links.length; i++) | 213 for (var i = 0; i < links.length; i++) |
| 237 { | 214 { |
| 238 if (typeof arguments[i + 1] == "string") | 215 if (typeof arguments[i + 1] == "string") |
| 239 { | 216 { |
| 240 links[i].href = arguments[i + 1]; | 217 links[i].href = arguments[i + 1]; |
| 241 links[i].setAttribute("target", "_blank"); | 218 links[i].setAttribute("target", "_blank"); |
| 242 } | 219 } |
| 243 else if (typeof arguments[i + 1] == "function") | 220 else if (typeof arguments[i + 1] == "function") |
| 244 { | 221 { |
| 245 links[i].href = "javascript:void(0);"; | 222 links[i].href = "javascript:void(0);"; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 262 { | 239 { |
| 263 var button = E("toggle-" + feature); | 240 var button = E("toggle-" + feature); |
| 264 if (isEnabled) | 241 if (isEnabled) |
| 265 button.classList.remove("off"); | 242 button.classList.remove("off"); |
| 266 else | 243 else |
| 267 button.classList.add("off"); | 244 button.classList.add("off"); |
| 268 } | 245 } |
| 269 | 246 |
| 270 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 247 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 271 })(); | 248 })(); |
| LEFT | RIGHT |