| 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       updateToggleButton("typo", Prefs.correctTypos); | 
|   68                        .getInterface(Ci.nsIDOMWindow); |   70  | 
|   69     if (topWnd.wrappedJSObject) |   71       var listener = function(name) | 
|   70       topWnd = topWnd.wrappedJSObject; |   72       { | 
|   71  |   73         if (name == "correctTypos") | 
|   72     // window.close() closes the entire window (bug 642604), make sure to close |   74           updateToggleButton("typo", Prefs.correctTypos); | 
|   73     // only a single tab instead. |   75       } | 
|   74     if ("BrowserUI" in topWnd) |   76       Prefs.addListener(listener); | 
|   75     { |   77       window.addEventListener("unload", function(event) | 
|   76       topWnd.BrowserUI.showPanel("addons-container"); |   78       { | 
|   77       function showOptions() |   79         Prefs.removeListener(listener); | 
|   78       { |   80       }, false); | 
|   79         if (!topWnd.ExtensionsView.getElementForAddon(Utils.addonID)) |   81  | 
|   80           Utils.runAsync(showOptions); |   82       E("toggle-typo").addEventListener("click", toggleTypoCorrectionEnabled, fa
     lse); | 
|   81         else |   83     } | 
|   82           topWnd.ExtensionsView.showOptions(Utils.addonID); |   84  | 
|   83       } |   85     // Set up feature buttons linked to subscriptions | 
|   84       showOptions(); |   86     featureSubscriptions.forEach(setToggleSubscriptionButton); | 
|   85     } |   87     var filterListener = function(action) | 
|   86   } |   88     { | 
|   87   else |   89       if (/^subscription\.(added|removed|disabled)$/.test(action)) | 
|   88     UI.openFiltersDialog(); |   90       { | 
|   89 } |   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); | 
 |  103  | 
 |  104     window.addEventListener("resize", onWindowResize, false); | 
 |  105     document.addEventListener("scroll", onScroll, false); | 
 |  106  | 
 |  107     onWindowResize(); | 
 |  108  | 
 |  109     initSocialLinks(null); | 
 |  110   } | 
 |  111  | 
 |  112   function onScroll() | 
 |  113   { | 
 |  114     var currentHeight = document.documentElement.scrollTop + document.body.scrol
     lTop + document.documentElement.clientHeight; | 
 |  115     shade.style.opacity = (document.documentElement.scrollHeight == currentHeigh
     t) ? "0.0" : "0.5"; | 
 |  116   } | 
 |  117  | 
 |  118   function onWindowResize() | 
 |  119   { | 
 |  120     onScroll(); | 
 |  121   } | 
 |  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  | 
 |  157   function scrollPage() | 
 |  158   { | 
 |  159     if (scrollTimer) | 
 |  160       stopScroll(); | 
 |  161  | 
 |  162     scrollTimer = setInterval(function() | 
 |  163     { | 
 |  164       window.scrollBy(0, 5); | 
 |  165     }, 20); | 
 |  166   } | 
 |  167  | 
 |  168   function stopScroll() | 
 |  169   { | 
 |  170     clearTimeout(scrollTimer); | 
 |  171     scrollTimer = null; | 
 |  172   } | 
 |  173  | 
 |  174   function openSharePopup(url) | 
 |  175   { | 
 |  176     var iframe = E("share-popup"); | 
 |  177     var glassPane = E("glass-pane"); | 
 |  178     var popupMessageReceived = false; | 
 |  179  | 
 |  180     var popupMessageListener = function(event) | 
 |  181     { | 
 |  182       var originFilter = Filter.fromText("||adblockplus.org^"); | 
 |  183       if (!originFilter.matches(event.origin, "OTHER", null, null)) | 
 |  184         return; | 
 |  185  | 
 |  186       var width = event.data.width; | 
 |  187       var height = event.data.height; | 
 |  188       iframe.width = width; | 
 |  189       iframe.height = height; | 
 |  190       iframe.style.marginTop = -height/2 + "px"; | 
 |  191       iframe.style.marginLeft = -width/2 + "px"; | 
 |  192       popupMessageReceived = true; | 
 |  193       window.removeEventListener("message", popupMessageListener); | 
 |  194     }; | 
 |  195     // Firefox requires last parameter to be true to be triggered by unprivilege
     d pages | 
 |  196     window.addEventListener("message", popupMessageListener, false, true); | 
 |  197  | 
 |  198     var popupLoadListener = function() | 
 |  199     { | 
 |  200       if (popupMessageReceived) | 
 |  201       { | 
 |  202         iframe.className = "visible"; | 
 |  203  | 
 |  204         var popupCloseListener = function() | 
 |  205         { | 
 |  206           iframe.className = glassPane.className = ""; | 
 |  207           document.removeEventListener("click", popupCloseListener); | 
 |  208         }; | 
 |  209         document.addEventListener("click", popupCloseListener, false); | 
 |  210       } | 
 |  211       else | 
 |  212       { | 
 |  213         glassPane.className = ""; | 
 |  214         window.removeEventListener("message", popupMessageListener); | 
 |  215       } | 
 |  216  | 
 |  217       iframe.removeEventListener("load", popupLoadListener); | 
 |  218     }; | 
 |  219     iframe.addEventListener("load", popupLoadListener, false); | 
 |  220  | 
 |  221     iframe.src = url; | 
 |  222     glassPane.className = "visible"; | 
 |  223   } | 
 |  224  | 
 |  225   function initSocialLinks(variant) | 
 |  226   { | 
 |  227     var networks = ["twitter", "facebook", "gplus"]; | 
 |  228     networks.forEach(function(network) | 
 |  229     { | 
 |  230       var link = E("share-" + network); | 
 |  231       link.addEventListener("click", function(e) | 
 |  232       { | 
 |  233         e.preventDefault(); | 
 |  234         openSharePopup(Utils.getDocLink("share-" + network) + "&variant=" + vari
     ant); | 
 |  235       }, false); | 
 |  236     }); | 
 |  237   } | 
 |  238  | 
 |  239   function setLinks(id) | 
 |  240   { | 
 |  241     var element = E(id); | 
 |  242     if (!element) | 
 |  243       return; | 
 |  244  | 
 |  245     var links = element.getElementsByTagName("a"); | 
 |  246     for (var i = 0; i < links.length; i++) | 
 |  247     { | 
 |  248       if (typeof arguments[i + 1] == "string") | 
 |  249       { | 
 |  250         links[i].href = arguments[i + 1]; | 
 |  251         links[i].setAttribute("target", "_blank"); | 
 |  252       } | 
 |  253       else if (typeof arguments[i + 1] == "function") | 
 |  254       { | 
 |  255         links[i].href = "javascript:void(0);"; | 
 |  256         links[i].addEventListener("click", arguments[i + 1], false); | 
 |  257       } | 
 |  258     } | 
 |  259   } | 
 |  260  | 
 |  261   function openFilters() | 
 |  262   { | 
 |  263     if (typeof UI != "undefined") | 
 |  264       UI.openFiltersDialog(); | 
 |  265     else | 
 |  266     { | 
 |  267       backgroundPage.openOptions(); | 
 |  268     } | 
 |  269   } | 
 |  270  | 
 |  271   function updateToggleButton(feature, isEnabled) | 
 |  272   { | 
 |  273     var button = E("toggle-" + feature); | 
 |  274     button.className = isEnabled ? "disable" : "enable"; | 
 |  275     button.textContent = i18n.getMessage(isEnabled ? "firstRun_action_disable" :
      "firstRun_action_enable"); | 
 |  276   } | 
 |  277  | 
 |  278   document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 
 |  279 })(); | 
| OLD | NEW |