Commit a12bf323 authored by Thomas Greiner's avatar Thomas Greiner

Issue 2374 - Implemented Tweaks section in options page

parent d6484f7d
......@@ -86,8 +86,11 @@ The behavior of this page is affected by a number of URL parameters:
errors when adding new filters on the options page
* `blockedURLs`: a comma-separated list of URLs that should be considered
blocked (necessary to test the check for blocked scripts in sharing buttons).
* `downloadStatus`: Sets downloadStatus parameter for filter lists, can be used
* `downloadStatus`: sets downloadStatus parameter for filter lists, can be used
to trigger various filter list download errors
* `platform=chromium`: shows the opt-out for the developer tools panel
* `safariContentBlocker=true`: sets Safari content blocker mock API
* `showNotificationUI=true`: simulates user having opted-out of notifications
[crowdin]: https://crowdin.com
......@@ -17,6 +17,35 @@
(function(global)
{
function Notifier()
{
this._listeners = [];
}
Notifier.prototype = {
_listeners: null,
addListener: function(listener)
{
if (this._listeners.indexOf(listener) < 0)
this._listeners.push(listener);
},
removeListener: function(listener)
{
var index = this._listeners.indexOf(listener);
if (index >= 0)
this._listeners.splice(index, 1);
},
triggerListeners: function()
{
var args = Array.prototype.slice.apply(arguments);
var listeners = this._listeners.slice();
for (var i = 0; i < listeners.length; i++)
listeners[i].apply(null, args);
}
};
function updateFromURL(data)
{
if (window.location.search)
......@@ -37,7 +66,9 @@
filterlistsReinitialized: false,
addSubscription: false,
filterError: false,
downloadStatus: "synchronize_ok"
downloadStatus: "synchronize_ok",
showNotificationUI: false,
safariContentBlocker: false
};
updateFromURL(params);
......@@ -62,7 +93,45 @@
modules.prefs = {
Prefs: {
"subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org/exceptionrules.txt"
onChanged: new Notifier()
}
};
var prefs = {
notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [],
notifications_showui: params.showNotificationUI,
safari_contentblocker: false,
shouldShowBlockElementMenu: true,
show_devtools_panel: true,
subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exceptionrules.txt"
};
Object.keys(prefs).forEach(function(key)
{
Object.defineProperty(modules.prefs.Prefs, key, {
get: function()
{
return prefs[key];
},
set: function(value)
{
prefs[key] = value;
modules.prefs.Prefs.onChanged.triggerListeners(key);
return prefs[key];
}
});
});
modules.notification = {
Notification: {
toggleIgnoreCategory: function(category)
{
var categories = prefs.notifications_ignoredcategories;
var index = categories.indexOf(category);
if (index == -1)
categories.push(category);
else
categories.splice(index, 1);
modules.prefs.Prefs.notifications_ignoredcategories = categories;
}
}
};
......@@ -243,30 +312,8 @@
}
};
var notifierListeners = [];
modules.filterNotifier = {
FilterNotifier: {
addListener: function(listener)
{
if (notifierListeners.indexOf(listener) < 0)
notifierListeners.push(listener);
},
removeListener: function(listener)
{
var index = notifierListeners.indexOf(listener);
if (index >= 0)
notifierListeners.splice(index, 1);
},
triggerListeners: function()
{
var args = Array.prototype.slice.apply(arguments);
var listeners = notifierListeners.slice();
for (var i = 0; i < listeners.length; i++)
listeners[i].apply(null, args);
}
}
FilterNotifier: new Notifier()
};
modules.info = {
......@@ -419,4 +466,13 @@
}
});
});
if (params.safariContentBlocker)
{
global.safari = {
extension: {
setContentBlocker: function() {}
}
};
}
})(this);
......@@ -141,7 +141,19 @@
},
"options_tweaks_blockElement": {
"description": "Show block Element option in Advanced tab",
"message": "Show <a>Block Element</a> right-click menu item"
"message": "Show Block Element right-click menu item"
},
"options_tweaks_showDevToolsPanel": {
"description": "Show developer tools panel option in Advanced tab",
"message": "Show 'Adblock Plus' panel in the developer tools"
},
"options_tweaks_showNotifications": {
"description": "Notification opt-out option in Advanced tab",
"message": "Show useful notifications"
},
"options_tweaks_safariContentBlocker": {
"description": "Switch between classic and Safari's Content Blocking",
"message": "Use Safari's native Content Blocking (experimental)"
},
"options_filterList_title": {
"description": "Section title in Advanced tab",
......@@ -221,11 +233,11 @@
},
"options_customFilters_title": {
"description": "Custom filters option name in Advanced tab",
"message": "Blocking rules"
"message": "Filter rules"
},
"options_customFilters_textbox_placeholder": {
"description": "Adding custom filter textbox placeholder text in Advanced tab",
"message": "add your blocking rule here"
"message": "add your filter rule here"
},
"options_customFilter_edit": {
"description": "Label for editing custom filter in Advanced tab",
......@@ -297,7 +309,7 @@
},
"options_dialog_create_own_list": {
"description": "Button in custom subscription modal dialog",
"message": "create own blocking rules"
"message": "create own filter rules"
},
"options_dialog_language_title": {
"description": "Button in gerenal tab",
......
......@@ -26,6 +26,7 @@
var FilterNotifier = require("filterNotifier").FilterNotifier;
var defaultMatcher = require("matcher").defaultMatcher;
var CSSRules = require("cssRules").CSSRules;
var NotificationStorage = require("notification").Notification;
var filterClasses = require("filterClasses");
var Filter = filterClasses.Filter;
......@@ -33,6 +34,7 @@
var RegExpFilter = filterClasses.RegExpFilter;
var Synchronizer = require("synchronizer").Synchronizer;
var info = require("info");
var subscriptionClasses = require("subscriptionClasses");
var Subscription = subscriptionClasses.Subscription;
var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
......@@ -54,6 +56,7 @@
var messageTypes = {
"app": "app.listen",
"filter": "filters.listen",
"pref": "prefs.listen",
"subscription": "subscriptions.listen"
};
......@@ -107,18 +110,21 @@
sendMessage(type, action, args);
}
function onPrefChange(name)
{
sendMessage("pref", name, [Prefs[name]]);
}
global.ext.onMessage.addListener(function(message, sender, callback)
{
var listenerFilters = null;
switch (message.type)
if (/\.listen$/.test(message.type))
{
case "app.listen":
case "filters.listen":
case "subscriptions.listen":
if (!changeListeners)
{
changeListeners = new global.ext.PageMap();
FilterNotifier.addListener(onFilterChange);
Prefs.onChanged.addListener(onPrefChange);
}
listenerFilters = changeListeners.get(sender.page);
......@@ -127,7 +133,6 @@
listenerFilters = Object.create(null);
changeListeners.set(sender.page, listenerFilters);
}
break;
}
switch (message.type)
......@@ -153,7 +158,6 @@
// Expected exception, this module doesn't exist on Firefox
}
var info = require("info");
callback({
filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitialized : false,
legacySafariVersion: (info.platform == "safari" && (
......@@ -176,7 +180,16 @@
}
else if (message.what == "addonVersion")
{
callback(require("info").addonVersion);
callback(info.addonVersion);
}
else if (message.what == "features")
{
callback({
devToolsPanel: info.platform == "chromium",
safariContentBlocker: "safari" in global
&& "extension" in global.safari
&& "setContentBlocker" in global.safari.extension
});
}
else
callback(null);
......@@ -298,6 +311,18 @@
case "prefs.get":
callback(Prefs[message.key]);
break;
case "prefs.listen":
if (message.filter)
listenerFilters.pref = message.filter;
else
delete listenerFilters.pref;
break;
case "prefs.toggle":
if (message.key == "notifications_ignoredcategories")
NotificationStorage.toggleIgnoreCategory("*");
else
Prefs[message.key] = !Prefs[message.key];
break;
case "subscriptions.add":
if (message.url in FilterStorage.knownSubscriptions)
return;
......
......@@ -217,13 +217,26 @@
<span class="i18n_options_tweaks_title"></span>
<a class="i18n_options_readMore tooltip"></a>
</h1>
<ul class="table">
<li>
<button role="checkbox" id="easylist"></button>
<span id="block-element-explanation" class="i18n_options_tweaks_blockElement"></span>
<ul id="tweaks" class="table">
<li data-pref="shouldShowBlockElementMenu">
<button role="checkbox" data-action="toggle-pref"></button>
<span class="i18n_options_tweaks_blockElement"></span>
</li>
<li data-pref="show_devtools_panel">
<button role="checkbox" data-action="toggle-pref"></button>
<span class="i18n_options_tweaks_showDevToolsPanel"></span>
</li>
<li data-pref="notifications_ignoredcategories">
<button role="checkbox" data-action="toggle-pref"></button>
<span class="i18n_options_tweaks_showNotifications"></span>
</li>
<li data-pref="safari_contentblocker">
<button role="checkbox" data-action="toggle-pref"></button>
<span class="i18n_options_tweaks_safariContentBlocker"></span>
</li>
</ul>
</div>
<div>
<h1>
<span class="i18n_options_filterList_title"></span>
......
......@@ -602,6 +602,13 @@
document.body.setAttribute("data-tab",
element.getAttribute("data-tab"));
break;
case "toggle-pref":
ext.backgroundPage.sendMessage(
{
type: "prefs.toggle",
key: findParentData(element, "pref", false)
});
break;
case "update-all-subscriptions":
ext.backgroundPage.sendMessage(
{
......@@ -690,6 +697,29 @@
}, false);
// Advanced tab
var tweaks = document.querySelectorAll("#tweaks li[data-pref]");
tweaks = Array.prototype.map.call(tweaks, function(checkbox)
{
return checkbox.getAttribute("data-pref");
});
tweaks.forEach(function(key)
{
getPref(key, function(value)
{
onPrefMessage(key, value);
});
});
ext.backgroundPage.sendMessage(
{
type: "app.get",
what: "features"
},
function(features)
{
hidePref("show_devtools_panel", !features.devToolsPanel);
hidePref("safari_contentblocker", !features.safariContentBlocker);
});
var filterTextbox = document.querySelector("#custom-filters-add input");
placeholderValue = getMessage("options_customFilters_textbox_placeholder");
filterTextbox.setAttribute("placeholder", placeholderValue);
......@@ -846,17 +876,12 @@
function getAcceptableAdsURL(callback)
{
ext.backgroundPage.sendMessage(
{
type: "prefs.get",
key: "subscriptions_exceptionsurl"
},
function(value)
getPref("subscriptions_exceptionsurl", function(value)
{
getAcceptableAdsURL = function(callback)
{
callback(value);
}
};
getAcceptableAdsURL(callback);
});
}
......@@ -956,6 +981,58 @@
}
}
function hidePref(key, value)
{
var element = document.querySelector("[data-pref='" + key + "']");
if (element)
element.setAttribute("aria-hidden", value);
}
function getPref(key, callback)
{
var checkPref = getPref.checks[key] || getPref.checkNone;
checkPref(function(isActive)
{
if (!isActive)
{
hidePref(key, !isActive);
return;
}
ext.backgroundPage.sendMessage(
{
type: "prefs.get",
key: key
}, callback);
});
}
getPref.checkNone = function(callback)
{
callback(true);
};
getPref.checks =
{
notifications_ignoredcategories: function(callback)
{
getPref("notifications_showui", callback);
}
};
function onPrefMessage(key, value)
{
var checkbox = document.querySelector("[data-pref='" + key + "'] button[role='checkbox']");
if (checkbox)
{
if (key == "notifications_ignoredcategories")
value = (value.indexOf("*") == -1);
checkbox.setAttribute("aria-checked", value);
}
else if (key == "notifications_showui")
hidePref("notifications_ignoredcategories", !value);
}
function onShareLinkClick(e)
{
e.preventDefault();
......@@ -1014,6 +1091,9 @@
case "filters.listen":
onFilterMessage(message.action, message.args[0]);
break;
case "prefs.listen":
onPrefMessage(message.action, message.args[0]);
break;
case "subscriptions.listen":
onSubscriptionMessage(message.action, message.args[0]);
break;
......@@ -1031,9 +1111,17 @@
filter: ["added", "loaded", "removed"]
});
ext.backgroundPage.sendMessage(
{
type: "prefs.listen",
filter: ["notifications_ignoredcategories", "notifications_showui",
"safari_contentblocker", "show_devtools_panel",
"shouldShowBlockElementMenu"]
});
ext.backgroundPage.sendMessage(
{
type: "subscriptions.listen",
filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title"]
filter: ["added", "disabled", "homepage", "lastDownload", "removed",
"title"]
});
window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
......
......@@ -52,6 +52,7 @@ body
margin: 20px 10px;
font-family: "Source Sans Pro", sans-serif;
font-size: 14px;
color: #494949;
}
h1
......@@ -80,6 +81,11 @@ hr
margin: 0px;
}
[aria-hidden="true"]
{
display: none !important;
}
input[type="search"]::-webkit-search-cancel-button
{
display: none;
......@@ -606,6 +612,11 @@ button[role="checkbox"],
Advanced tab content
*/
#tweaks.table li
{
padding-bottom: 0px;
}
#filter-lists > div
{
display: none;
......@@ -872,7 +883,7 @@ body[data-tab="advanced-customFilters"] #content-advanced [data-tab="advanced-cu
Tooltips
*/
.tooltip, #block-element-explanation a
.tooltip
{
border-bottom: dashed 1px;
color: #3A7BA6;
......@@ -905,15 +916,6 @@ body[data-tab="advanced-customFilters"] #content-advanced [data-tab="advanced-cu
-webkit-margin-start: 8px;
}
#block-element-explanation a
{
color: black;
border-bottom-color: #3A7BA6;
font-weight: 600;
-moz-padding-start: 0px;
-webkit-padding-start: 0px;
}
div[role="tooltip"]
{
background-color: rgba(45, 45, 45, 0.95);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment