Index: options.js |
=================================================================== |
--- a/options.js |
+++ b/options.js |
@@ -1,6 +1,6 @@ |
/* |
* This file is part of Adblock Plus <https://adblockplus.org/>, |
- * Copyright (C) 2006-2016 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,45 +15,39 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
+/* global $, i18n, i18nTimeDateStrings */ |
+ |
"use strict"; |
/** |
* Creates a wrapping function used to conveniently send a type of message. |
* |
* @param {Object} baseMessage The part of the message that's always sent |
- * @param {..string} paramKeys Any message keys that have dynamic values. The |
- * returned function will take the corresponding |
- * values as arguments. |
- * @return The generated messaging function, optionally taking any values as |
- * specified by the paramKeys and finally an optional callback. |
- * (Although the value arguments are optional their index must be |
- * maintained. E.g. if you omit the first value you must omit the |
- * second too.) |
+ * @param {...string} paramKeys Any message keys that have dynamic values. The |
+ * returned function will take the corresponding |
+ * values as arguments. |
+ * @return {function} The generated messaging function, optionally |
+ * taking any values as specified by the paramKeys |
+ * and finally an optional callback. (Although the |
+ * value arguments are optional their index must be |
+ * maintained. E.g. if you omit the first value you |
+ * must omit the second too.) |
*/ |
-function wrapper(baseMessage /* , [paramKeys] */) |
+function wrapper(baseMessage, ...paramKeys) |
{ |
- let paramKeys = []; |
- for (let i = 1; i < arguments.length; i++) |
- paramKeys.push(arguments[i]); |
- |
- return function(/* [paramValues], callback */) |
+ return function(...paramValues /* , callback */) |
{ |
- let message = Object.create(null); |
- for (let key in baseMessage) |
- if (baseMessage.hasOwnProperty(key)) |
- message[key] = baseMessage[key]; |
- |
- let paramValues = []; |
+ let message = Object.assign(Object.create(null), baseMessage); |
let callback; |
- if (arguments.length > 0) |
+ if (paramValues.length > 0) |
{ |
- let lastArg = arguments[arguments.length - 1]; |
+ let lastArg = paramValues[paramValues.length - 1]; |
if (typeof lastArg == "function") |
callback = lastArg; |
- for (let i = 0; i < arguments.length - (callback ? 1 : 0); i++) |
- message[paramKeys[i]] = arguments[i]; |
+ for (let i = 0; i < paramValues.length - (callback ? 1 : 0); i++) |
+ message[paramKeys[i]] = paramValues[i]; |
} |
// Edge 38.14393 silently fails when sendMessage is called with a callback |
@@ -84,9 +78,19 @@ |
const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); |
const removeFilter = wrapper({type: "filters.remove"}, "text"); |
-const whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; |
+const whitelistedDomainRegexp = /^@@\|\|([^/:]+)\^\$document$/; |
+const statusMessages = new Map([ |
+ ["synchronize_invalid_url", |
+ "filters_subscription_lastDownload_invalidURL"], |
+ ["synchronize_connection_error", |
+ "filters_subscription_lastDownload_connectionError"], |
+ ["synchronize_invalid_data", |
+ "filters_subscription_lastDownload_invalidData"], |
+ ["synchronize_checksum_mismatch", |
+ "filters_subscription_lastDownload_checksumMismatch"] |
+]); |
+ |
let delayedSubscriptionSelection = null; |
- |
let acceptableAdsUrl; |
// Loads options from localStorage and sets UI elements accordingly |
@@ -153,9 +157,9 @@ |
if (!features.devToolsPanel) |
document.getElementById("showDevtoolsPanelContainer").hidden = true; |
}); |
- getPref("notifications_showui", notifications_showui => |
+ getPref("notifications_showui", showNotificationsUI => |
{ |
- if (!notifications_showui) |
+ if (!showNotificationsUI) |
document.getElementById("shouldShowNotificationsContainer").hidden = true; |
}); |
@@ -164,19 +168,16 @@ |
type: "app.listen", |
filter: ["addSubscription", "focusSection"] |
}); |
- ext.backgroundPage.sendMessage( |
- { |
+ ext.backgroundPage.sendMessage({ |
type: "filters.listen", |
filter: ["added", "loaded", "removed"] |
}); |
- ext.backgroundPage.sendMessage( |
- { |
+ ext.backgroundPage.sendMessage({ |
type: "prefs.listen", |
filter: ["notifications_ignoredcategories", "notifications_showui", |
"show_devtools_panel", "shouldShowBlockElementMenu"] |
}); |
- ext.backgroundPage.sendMessage( |
- { |
+ ext.backgroundPage.sendMessage({ |
type: "subscriptions.listen", |
filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
"title", "downloadStatus", "downloading"] |
@@ -319,7 +320,7 @@ |
list.selectedIndex = selectedIndex; |
if (delayedSubscriptionSelection) |
- startSubscriptionSelection.apply(null, delayedSubscriptionSelection); |
+ startSubscriptionSelection(...delayedSubscriptionSelection); |
}); |
} |
@@ -367,7 +368,8 @@ |
addSubscription(data.url, data.title, data.homepage); |
else |
{ |
- let url = document.getElementById("customSubscriptionLocation").value.trim(); |
+ let url = document.getElementById("customSubscriptionLocation") |
+ .value.trim(); |
if (!/^https?:/i.test(url)) |
{ |
alert(i18n.getMessage("global_subscription_invalid_location")); |
@@ -395,8 +397,10 @@ |
function findSubscriptionElement(subscription) |
{ |
for (let child of document.getElementById("filterLists").childNodes) |
+ { |
if (child._subscription.url == subscription.url) |
return child; |
+ } |
return null; |
} |
@@ -421,29 +425,28 @@ |
let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; |
lastUpdate.classList.remove("error"); |
- let downloadStatus = subscription.downloadStatus; |
+ let {downloadStatus} = subscription; |
if (subscription.isDownloading) |
{ |
- lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_inProgress"); |
+ lastUpdate.textContent = i18n.getMessage( |
+ "filters_subscription_lastDownload_inProgress" |
+ ); |
} |
else if (downloadStatus && downloadStatus != "synchronize_ok") |
{ |
- let map = |
- { |
- "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL", |
- "synchronize_connection_error": "filters_subscription_lastDownload_connectionError", |
- "synchronize_invalid_data": "filters_subscription_lastDownload_invalidData", |
- "synchronize_checksum_mismatch": "filters_subscription_lastDownload_checksumMismatch" |
- }; |
- if (downloadStatus in map) |
- lastUpdate.textContent = i18n.getMessage(map[downloadStatus]); |
- else |
- lastUpdate.textContent = downloadStatus; |
- lastUpdate.classList.add("error"); |
+ if (statusMessages.has(downloadStatus)) |
+ { |
+ lastUpdate.textContent = i18n.getMessage( |
+ statusMessages.get(downloadStatus) |
+ ); |
+ } |
+ else |
+ lastUpdate.textContent = downloadStatus; |
+ lastUpdate.classList.add("error"); |
} |
else if (subscription.lastDownload > 0) |
{ |
- let timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); |
+ let timeDate = i18nTimeDateStrings(subscription.lastDownload * 1000); |
let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); |
lastUpdate.textContent = i18n.getMessage(messageID, timeDate); |
} |
@@ -486,7 +489,9 @@ |
switch (key) |
{ |
case "notifications_showui": |
- document.getElementById("shouldShowNotificationsContainer").hidden = !value; |
+ document.getElementById( |
+ "shouldShowNotificationsContainer" |
+ ).hidden = !value; |
return; |
case "notifications_ignoredcategories": |
key = "shouldShowNotifications"; |
@@ -543,7 +548,9 @@ |
{ |
event.preventDefault(); |
- let domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g, ""); |
+ let domain = document.getElementById( |
+ "newWhitelistDomain" |
+ ).value.replace(/\s/g, ""); |
document.getElementById("newWhitelistDomain").value = ""; |
if (!domain) |
return; |
@@ -573,8 +580,10 @@ |
event.preventDefault(); |
let remove = []; |
for (let option of document.getElementById("excludedDomainsBox").options) |
+ { |
if (option.selected) |
remove.push(option.value); |
+ } |
if (!remove.length) |
return; |
@@ -586,7 +595,8 @@ |
function removeSelectedFilters(event) |
{ |
event.preventDefault(); |
- for (let option of document.querySelectorAll("#userFiltersBox > option:checked")) |
+ let options = document.querySelectorAll("#userFiltersBox > option:checked"); |
+ for (let option of options) |
removeFilter(option.value); |
} |
@@ -641,7 +651,9 @@ |
element.removeAttribute("id"); |
element._subscription = subscription; |
- let removeButton = element.getElementsByClassName("subscriptionRemoveButton")[0]; |
+ let removeButton = element.getElementsByClassName( |
+ "subscriptionRemoveButton" |
+ )[0]; |
removeButton.setAttribute("title", removeButton.textContent); |
removeButton.textContent = "\xD7"; |
removeButton.addEventListener("click", () => |
@@ -670,7 +682,7 @@ |
document.getElementById("filterLists").appendChild(element); |
} |
-function setLinks(id) |
+function setLinks(id, ...args) |
{ |
let element = document.getElementById(id); |
if (!element) |
@@ -679,15 +691,15 @@ |
let links = element.getElementsByTagName("a"); |
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); |
} |
} |
} |