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: ...@@ -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 errors when adding new filters on the options page
* `blockedURLs`: a comma-separated list of URLs that should be considered * `blockedURLs`: a comma-separated list of URLs that should be considered
blocked (necessary to test the check for blocked scripts in sharing buttons). 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 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 [crowdin]: https://crowdin.com
...@@ -17,6 +17,35 @@ ...@@ -17,6 +17,35 @@
(function(global) (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) function updateFromURL(data)
{ {
if (window.location.search) if (window.location.search)
...@@ -37,7 +66,9 @@ ...@@ -37,7 +66,9 @@
filterlistsReinitialized: false, filterlistsReinitialized: false,
addSubscription: false, addSubscription: false,
filterError: false, filterError: false,
downloadStatus: "synchronize_ok" downloadStatus: "synchronize_ok",
showNotificationUI: false,
safariContentBlocker: false
}; };
updateFromURL(params); updateFromURL(params);
...@@ -62,7 +93,45 @@ ...@@ -62,7 +93,45 @@
modules.prefs = { modules.prefs = {
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 @@ ...@@ -243,30 +312,8 @@
} }
}; };
var notifierListeners = [];
modules.filterNotifier = { modules.filterNotifier = {
FilterNotifier: { FilterNotifier: new Notifier()
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);
}
}
}; };
modules.info = { modules.info = {
...@@ -419,4 +466,13 @@ ...@@ -419,4 +466,13 @@
} }
}); });
}); });
if (params.safariContentBlocker)
{
global.safari = {
extension: {
setContentBlocker: function() {}
}
};
}
})(this); })(this);
...@@ -141,7 +141,19 @@ ...@@ -141,7 +141,19 @@
}, },
"options_tweaks_blockElement": { "options_tweaks_blockElement": {
"description": "Show block Element option in Advanced tab", "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": { "options_filterList_title": {
"description": "Section title in Advanced tab", "description": "Section title in Advanced tab",
...@@ -221,11 +233,11 @@ ...@@ -221,11 +233,11 @@
}, },
"options_customFilters_title": { "options_customFilters_title": {
"description": "Custom filters option name in Advanced tab", "description": "Custom filters option name in Advanced tab",
"message": "Blocking rules" "message": "Filter rules"
}, },
"options_customFilters_textbox_placeholder": { "options_customFilters_textbox_placeholder": {
"description": "Adding custom filter textbox placeholder text in Advanced tab", "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": { "options_customFilter_edit": {
"description": "Label for editing custom filter in Advanced tab", "description": "Label for editing custom filter in Advanced tab",
...@@ -297,7 +309,7 @@ ...@@ -297,7 +309,7 @@
}, },
"options_dialog_create_own_list": { "options_dialog_create_own_list": {
"description": "Button in custom subscription modal dialog", "description": "Button in custom subscription modal dialog",
"message": "create own blocking rules" "message": "create own filter rules"
}, },
"options_dialog_language_title": { "options_dialog_language_title": {
"description": "Button in gerenal tab", "description": "Button in gerenal tab",
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
var FilterNotifier = require("filterNotifier").FilterNotifier; var FilterNotifier = require("filterNotifier").FilterNotifier;
var defaultMatcher = require("matcher").defaultMatcher; var defaultMatcher = require("matcher").defaultMatcher;
var CSSRules = require("cssRules").CSSRules; var CSSRules = require("cssRules").CSSRules;
var NotificationStorage = require("notification").Notification;
var filterClasses = require("filterClasses"); var filterClasses = require("filterClasses");
var Filter = filterClasses.Filter; var Filter = filterClasses.Filter;
...@@ -33,6 +34,7 @@ ...@@ -33,6 +34,7 @@
var RegExpFilter = filterClasses.RegExpFilter; var RegExpFilter = filterClasses.RegExpFilter;
var Synchronizer = require("synchronizer").Synchronizer; var Synchronizer = require("synchronizer").Synchronizer;
var info = require("info");
var subscriptionClasses = require("subscriptionClasses"); var subscriptionClasses = require("subscriptionClasses");
var Subscription = subscriptionClasses.Subscription; var Subscription = subscriptionClasses.Subscription;
var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
...@@ -54,6 +56,7 @@ ...@@ -54,6 +56,7 @@
var messageTypes = { var messageTypes = {
"app": "app.listen", "app": "app.listen",
"filter": "filters.listen", "filter": "filters.listen",
"pref": "prefs.listen",
"subscription": "subscriptions.listen" "subscription": "subscriptions.listen"
}; };
...@@ -107,27 +110,29 @@ ...@@ -107,27 +110,29 @@
sendMessage(type, action, args); sendMessage(type, action, args);
} }
function onPrefChange(name)
{
sendMessage("pref", name, [Prefs[name]]);
}
global.ext.onMessage.addListener(function(message, sender, callback) global.ext.onMessage.addListener(function(message, sender, callback)
{ {
var listenerFilters = null; var listenerFilters = null;
switch (message.type) if (/\.listen$/.test(message.type))
{ {
case "app.listen": if (!changeListeners)
case "filters.listen": {
case "subscriptions.listen": changeListeners = new global.ext.PageMap();
if (!changeListeners) FilterNotifier.addListener(onFilterChange);
{ Prefs.onChanged.addListener(onPrefChange);
changeListeners = new global.ext.PageMap(); }
FilterNotifier.addListener(onFilterChange);
}
listenerFilters = changeListeners.get(sender.page); listenerFilters = changeListeners.get(sender.page);
if (!listenerFilters) if (!listenerFilters)
{ {
listenerFilters = Object.create(null); listenerFilters = Object.create(null);
changeListeners.set(sender.page, listenerFilters); changeListeners.set(sender.page, listenerFilters);
} }
break;
} }
switch (message.type) switch (message.type)
...@@ -153,7 +158,6 @@ ...@@ -153,7 +158,6 @@
// Expected exception, this module doesn't exist on Firefox // Expected exception, this module doesn't exist on Firefox
} }
var info = require("info");
callback({ callback({
filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitialized : false, filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitialized : false,
legacySafariVersion: (info.platform == "safari" && ( legacySafariVersion: (info.platform == "safari" && (
...@@ -176,7 +180,16 @@ ...@@ -176,7 +180,16 @@
} }
else if (message.what == "addonVersion") 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 else
callback(null); callback(null);
...@@ -298,6 +311,18 @@ ...@@ -298,6 +311,18 @@
case "prefs.get": case "prefs.get":
callback(Prefs[message.key]); callback(Prefs[message.key]);
break; 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": case "subscriptions.add":
if (message.url in FilterStorage.knownSubscriptions) if (message.url in FilterStorage.knownSubscriptions)
return; return;
......
...@@ -217,13 +217,26 @@ ...@@ -217,13 +217,26 @@
<span class="i18n_options_tweaks_title"></span> <span class="i18n_options_tweaks_title"></span>
<a class="i18n_options_readMore tooltip"></a> <a class="i18n_options_readMore tooltip"></a>
</h1> </h1>
<ul class="table"> <ul id="tweaks" class="table">
<li> <li data-pref="shouldShowBlockElementMenu">
<button role="checkbox" id="easylist"></button> <button role="checkbox" data-action="toggle-pref"></button>
<span id="block-element-explanation" class="i18n_options_tweaks_blockElement"></span> <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> </li>
</ul> </ul>
</div> </div>
<div> <div>
<h1> <h1>
<span class="i18n_options_filterList_title"></span> <span class="i18n_options_filterList_title"></span>
......
...@@ -602,6 +602,13 @@ ...@@ -602,6 +602,13 @@
document.body.setAttribute("data-tab", document.body.setAttribute("data-tab",
element.getAttribute("data-tab")); element.getAttribute("data-tab"));
break; break;
case "toggle-pref":
ext.backgroundPage.sendMessage(
{
type: "prefs.toggle",
key: findParentData(element, "pref", false)
});
break;
case "update-all-subscriptions": case "update-all-subscriptions":
ext.backgroundPage.sendMessage( ext.backgroundPage.sendMessage(
{ {
...@@ -690,6 +697,29 @@ ...@@ -690,6 +697,29 @@
}, false); }, false);
// Advanced tab // 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"); var filterTextbox = document.querySelector("#custom-filters-add input");
placeholderValue = getMessage("options_customFilters_textbox_placeholder"); placeholderValue = getMessage("options_customFilters_textbox_placeholder");
filterTextbox.setAttribute("placeholder", placeholderValue); filterTextbox.setAttribute("placeholder", placeholderValue);
...@@ -846,17 +876,12 @@ ...@@ -846,17 +876,12 @@
function getAcceptableAdsURL(callback) function getAcceptableAdsURL(callback)
{ {
ext.backgroundPage.sendMessage( getPref("subscriptions_exceptionsurl", function(value)
{
type: "prefs.get",
key: "subscriptions_exceptionsurl"
},
function(value)
{ {
getAcceptableAdsURL = function(callback) getAcceptableAdsURL = function(callback)
{ {
callback(value); callback(value);
} };
getAcceptableAdsURL(callback); getAcceptableAdsURL(callback);
}); });
} }
...@@ -956,6 +981,58 @@ ...@@ -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) function onShareLinkClick(e)
{ {
e.preventDefault(); e.preventDefault();
...@@ -1014,6 +1091,9 @@ ...@@ -1014,6 +1091,9 @@
case "filters.listen": case "filters.listen":
onFilterMessage(message.action, message.args[0]); onFilterMessage(message.action, message.args[0]);
break; break;
case "prefs.listen":
onPrefMessage(message.action, message.args[0]);
break;
case "subscriptions.listen": case "subscriptions.listen":
onSubscriptionMessage(message.action, message.args[0]); onSubscriptionMessage(message.action, message.args[0]);
break; break;
...@@ -1031,9 +1111,17 @@ ...@@ -1031,9 +1111,17 @@
filter: ["added", "loaded", "removed"] filter: ["added", "loaded", "removed"]
}); });
ext.backgroundPage.sendMessage( ext.backgroundPage.sendMessage(
{
type: "prefs.listen",
filter: ["notifications_ignoredcategories", "notifications_showui",
"safari_contentblocker", "show_devtools_panel",
"shouldShowBlockElementMenu"]
});
ext.backgroundPage.sendMessage(
{ {
type: "subscriptions.listen", type: "subscriptions.listen",
filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title"] filter: ["added", "disabled", "homepage", "lastDownload", "removed",
"title"]
}); });
window.addEventListener("DOMContentLoaded", onDOMLoaded, false); window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
......
...@@ -52,6 +52,7 @@ body ...@@ -52,6 +52,7 @@ body
margin: 20px 10px; margin: 20px 10px;
font-family: "Source Sans Pro", sans-serif; font-family: "Source Sans Pro", sans-serif;
font-size: 14px; font-size: 14px;
color: #494949;
} }
h1 h1
...@@ -80,6 +81,11 @@ hr ...@@ -80,6 +81,11 @@ hr
margin: 0px; margin: 0px;
} }
[aria-hidden="true"]
{
display: none !important;
}
input[type="search"]::-webkit-search-cancel-button input[type="search"]::-webkit-search-cancel-button
{ {
display: none; display: none;
...@@ -606,6 +612,11 @@ button[role="checkbox"], ...@@ -606,6 +612,11 @@ button[role="checkbox"],
Advanced tab content Advanced tab content
*/ */
#tweaks.table li
{
padding-bottom: 0px;
}
#filter-lists > div #filter-lists > div
{ {
display: none; display: none;
...@@ -872,7 +883,7 @@ body[data-tab="advanced-customFilters"] #content-advanced [data-tab="advanced-cu ...@@ -872,7 +883,7 @@ body[data-tab="advanced-customFilters"] #content-advanced [data-tab="advanced-cu
Tooltips Tooltips
*/ */
.tooltip, #block-element-explanation a .tooltip
{ {
border-bottom: dashed 1px; border-bottom: dashed 1px;
color: #3A7BA6; color: #3A7BA6;
...@@ -905,15 +916,6 @@ body[data-tab="advanced-customFilters"] #content-advanced [data-tab="advanced-cu ...@@ -905,15 +916,6 @@ body[data-tab="advanced-customFilters"] #content-advanced [data-tab="advanced-cu
-webkit-margin-start: 8px; -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"] div[role="tooltip"]
{ {
background-color: rgba(45, 45, 45, 0.95); 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