diff options
Diffstat (limited to 'data/extensions/spyblock@gnu.org/chrome/content/ui/firstRun.js')
-rw-r--r-- | data/extensions/spyblock@gnu.org/chrome/content/ui/firstRun.js | 212 |
1 files changed, 31 insertions, 181 deletions
diff --git a/data/extensions/spyblock@gnu.org/chrome/content/ui/firstRun.js b/data/extensions/spyblock@gnu.org/chrome/content/ui/firstRun.js index 3a11a2e..14d3db2 100644 --- a/data/extensions/spyblock@gnu.org/chrome/content/ui/firstRun.js +++ b/data/extensions/spyblock@gnu.org/chrome/content/ui/firstRun.js @@ -1,6 +1,6 @@ /* * This file is part of Adblock Plus <https://adblockplus.org/>, - * Copyright (C) 2006-2015 Eyeo GmbH + * Copyright (C) 2006-2017 eyeo GmbH * * Adblock Plus is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -15,52 +15,18 @@ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. */ +/* globals checkShareResource, getDocLink, openSharePopup, E */ + "use strict"; (function() { - function E(id) - { - return document.getElementById(id); - } - - // Load subscriptions for features - var featureSubscriptions = [ - { - feature: "malware", - homepage: "http://malwaredomains.com/", - title: "Malware Domains", - url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" - }, - { - feature: "social", - homepage: "https://www.fanboy.co.nz/", - title: "Fanboy's Social Blocking List", - url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" - }, - { - feature: "tracking", - homepage: "https://easylist.adblockplus.org/", - title: "EasyPrivacy", - url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" - } - ]; - - function getDocLink(link, callback) - { - ext.backgroundPage.sendMessage({ - type: "app.get", - what: "doclink", - link: link - }, callback); - } - function onDOMLoaded() { // Set up logo image - var logo = E("logo"); + let logo = E("logo"); logo.src = "skin/abp-128.png"; - var errorCallback = function() + let errorCallback = function() { logo.removeEventListener("error", errorCallback, false); // We are probably in Chrome/Opera/Safari, the image has a different path. @@ -69,22 +35,22 @@ logo.addEventListener("error", errorCallback, false); // Set up URLs - getDocLink("donate", function(link) + getDocLink("donate", (link) => { E("donate").href = link; }); - getDocLink("contributors", function(link) + getDocLink("contributors", (link) => { E("contributors").href = link; }); - getDocLink("acceptable_ads_criteria", function(link) + getDocLink("acceptable_ads_criteria", (link) => { - setLinks("acceptableAdsExplanation", link, openFilters); + setLinks("acceptable-ads-explanation", link, openFilters); }); - getDocLink("contribute", function(link) + getDocLink("contribute", (link) => { setLinks("share-headline", link); }); @@ -92,39 +58,22 @@ ext.backgroundPage.sendMessage({ type: "app.get", what: "issues" - }, function(issues) + }, (issues) => { - // Show warning if data corruption was detected - if (issues.seenDataCorruption) - { - E("dataCorruptionWarning").removeAttribute("hidden"); - getDocLink("knownIssuesChrome_filterstorage", function(link) - { - setLinks("dataCorruptionWarning", link); - }); - } - // Show warning if filterlists settings were reinitialized if (issues.filterlistsReinitialized) { E("filterlistsReinitializedWarning").removeAttribute("hidden"); setLinks("filterlistsReinitializedWarning", openFilters); } - - if (issues.legacySafariVersion) - E("legacySafariWarning").removeAttribute("hidden"); }); - // Set up feature buttons linked to subscriptions - featureSubscriptions.forEach(initToggleSubscriptionButton); - updateToggleButtons(); updateSocialLinks(); - ext.onMessage.addListener(function(message) + ext.onMessage.addListener((message) => { - if (message.type == "subscriptions.listen") + if (message.type == "subscriptions.respond") { - updateToggleButtons(); updateSocialLinks(); } }); @@ -134,127 +83,56 @@ }); } - function initToggleSubscriptionButton(featureSubscription) - { - var feature = featureSubscription.feature; - - var element = E("toggle-" + feature); - element.addEventListener("click", function(event) - { - ext.backgroundPage.sendMessage({ - type: "subscriptions.toggle", - url: featureSubscription.url, - title: featureSubscription.title, - homepage: featureSubscription.homepage - }); - }, false); - } - - function openSharePopup(url) - { - var iframe = E("share-popup"); - var glassPane = E("glass-pane"); - var popupMessageReceived = false; - - var popupMessageListener = function(event) - { - if (!/[.\/]adblockplus\.org$/.test(event.origin)) - return; - - var width = event.data.width; - var height = event.data.height; - iframe.width = width; - iframe.height = height; - iframe.style.marginTop = -height/2 + "px"; - iframe.style.marginLeft = -width/2 + "px"; - popupMessageReceived = true; - window.removeEventListener("message", popupMessageListener); - }; - // Firefox requires last parameter to be true to be triggered by unprivileged pages - window.addEventListener("message", popupMessageListener, false, true); - - var popupLoadListener = function() - { - if (popupMessageReceived) - { - iframe.className = "visible"; - - var popupCloseListener = function() - { - iframe.className = glassPane.className = ""; - document.removeEventListener("click", popupCloseListener); - }; - document.addEventListener("click", popupCloseListener, false); - } - else - { - glassPane.className = ""; - window.removeEventListener("message", popupMessageListener); - } - - iframe.removeEventListener("load", popupLoadListener); - }; - iframe.addEventListener("load", popupLoadListener, false); - - iframe.src = url; - glassPane.className = "visible"; - } - function updateSocialLinks() { - var networks = ["twitter", "facebook", "gplus"]; - networks.forEach(function(network) + for (let network of ["twitter", "facebook", "gplus"]) { - var link = E("share-" + network); - var message = { - type: "filters.blocked", - url: link.getAttribute("data-script"), - requestType: "SCRIPT", - docDomain: "adblockplus.org", - thirdParty: true - }; - ext.backgroundPage.sendMessage(message, function(blocked) + let link = E("share-" + network); + checkShareResource(link.getAttribute("data-script"), (isBlocked) => { // Don't open the share page if the sharing script would be blocked - if (blocked) + if (isBlocked) link.removeEventListener("click", onSocialLinkClick, false); else link.addEventListener("click", onSocialLinkClick, false); }); - }); + } } function onSocialLinkClick(event) { + if (window.matchMedia("(max-width: 970px)").matches) + return; + event.preventDefault(); - getDocLink(event.target.id, function(link) + getDocLink(event.target.id, (link) => { openSharePopup(link); }); } - function setLinks(id) + function setLinks(id, ...args) { - var element = E(id); + let element = E(id); if (!element) { return; } - var links = element.getElementsByTagName("a"); + let links = element.getElementsByTagName("a"); - for (var i = 0; i < links.length; i++) + for (let i = 0; i < links.length; i++) { - if (typeof arguments[i + 1] == "string") + if (typeof args[i] == "string") { - links[i].href = arguments[i + 1]; + links[i].href = args[i]; links[i].setAttribute("target", "_blank"); } - else if (typeof arguments[i + 1] == "function") + else if (typeof args[i] == "function") { links[i].href = "javascript:void(0);"; - links[i].addEventListener("click", arguments[i + 1], false); + links[i].addEventListener("click", args[i], false); } } } @@ -264,33 +142,5 @@ ext.backgroundPage.sendMessage({type: "app.open", what: "options"}); } - function updateToggleButtons() - { - ext.backgroundPage.sendMessage({ - type: "subscriptions.get", - downloadable: true, - ignoreDisabled: true - }, function(subscriptions) - { - var known = Object.create(null); - for (var i = 0; i < subscriptions.length; i++) - known[subscriptions[i].url] = true; - for (var i = 0; i < featureSubscriptions.length; i++) - { - var featureSubscription = featureSubscriptions[i]; - updateToggleButton(featureSubscription.feature, featureSubscription.url in known); - } - }); - } - - function updateToggleButton(feature, isEnabled) - { - var button = E("toggle-" + feature); - if (isEnabled) - button.classList.remove("off"); - else - button.classList.add("off"); - } - document.addEventListener("DOMContentLoaded", onDOMLoaded, false); -})(); +}()); |