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