1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Save state of the arrow menu in options page

Fixes #251
This commit is contained in:
kkapsner 2018-09-12 23:43:48 +02:00
parent 040acb311f
commit f73a4ee619
5 changed files with 77 additions and 5 deletions

View File

@ -23,6 +23,11 @@
hideContainer: true,
defaultValue: {}
},
{
name: "expandStatus",
expandContainer: true,
defaultValue: {}
},
{
name: "displayHiddenSettings",
defaultValue: false

View File

@ -40,6 +40,7 @@
const settings = {};
let urlContainer;
let hideContainer;
let expandContainer;
function isDefinitionInvalid(settingDefinition, newValue){
if (newValue === undefined && settingDefinition.optional){
@ -351,6 +352,40 @@
});
settingDefinition.hideAble = false;
}
if (settingDefinition.expandContainer){
expandContainer = settingDefinition;
let changeListeners = {};
settingDefinition.setExpandByName = function(name, value){
logging.verbose("set expand of", name, "to", value);
const expandStore = settingDefinition.get();
expandStore[name] = value;
settingDefinition.set(expandStore);
(changeListeners[name] || []).forEach(function(listener){
listener(value);
});
};
settingDefinition.getExpandByName = function(name){
const expandStore = settingDefinition.get();
return expandStore[name] || false;
};
settingDefinition.onExpandChange = function(name, listener){
if (!changeListeners[name]){
changeListeners[name] = [];
}
changeListeners[name].push(listener);
};
settingDefinition.on(function(event){
const value = event.newValue;
Object.keys(value).forEach(function(name){
if (value[name]){
(changeListeners[name] || []).forEach(function(listener){
listener(true);
});
}
});
});
}
});
scope.getDefinition = function(name){
@ -366,7 +401,8 @@
scope.getContainers = function(){
return {
url: Object.create(urlContainer),
hide: Object.create(hideContainer)
hide: Object.create(hideContainer),
expand: Object.create(expandContainer)
};
};

View File

@ -212,7 +212,7 @@
};
addSection();
const {hide: hideContainer} = settings.getContainers();
const {hide: hideContainer, expand: expandContainer} = settings.getContainers();
settingsDisplay.forEach(function(display){
if (typeof display === "string"){
addSection(display);
@ -248,6 +248,7 @@
}
if (setting){
setting.display = display;
let hideChangeListeners = [];
setting.setHide = function setHide(value){
if (hideContainer){
@ -279,6 +280,31 @@
});
}
let expandChangeListeners = [];
setting.setExpand = function setExpand(value){
if (expandContainer){
expandContainer.setExpandByName(display.name, value);
}
};
setting.onExpandChange = function(listener){
expandChangeListeners.push(listener);
};
setting.getExpand = function getExpand(){
if (expandContainer){
return expandContainer.getExpandByName(display.name);
}
else {
return false;
}
};
if (expandContainer){
expandContainer.onExpandChange(display.name, function(value){
expandChangeListeners.forEach(function(listener){
listener(value);
});
});
}
var row = optionsGui.createSettingRow(setting);
let section = lastSection;
section.addRow(row);

View File

@ -198,14 +198,17 @@
if (setting.urlSpecific && url === ""){
let container = document.createElement("div");
container.className = "urlValues collapsed";
container.className = "urlValues " + (setting.getExpand()? "expanded": "collapsed");
container.appendChild(input);
var collapser = document.createElement("span");
collapser.classList.add("collapser");
container.appendChild(collapser);
collapser.addEventListener("click", function(){
container.classList.toggle("collapsed");
container.classList.toggle("expanded");
setting.setExpand(!setting.getExpand());
});
setting.onExpandChange(function(value){
container.classList[value? "remove": "add"]("collapsed");
container.classList[value? "add": "remove"]("expanded");
});
let urlTable = document.createElement("table");
let caption = document.createElement("caption");

View File

@ -2,11 +2,13 @@ Version 0.5.4:
changes:
- converted "API whitelist" to "protected API features" (automatic settings migration)
- notification details are not stored by default
- settings page reorganized
new features:
- added save/load directly to/from file option
- added protection for DOMRect (getClientRects)
- added setting to control if notification details should be stored
- state of the arrow for url specific values is saved
fixes:
- window and audio API were always blocked when using any of the "block ..." modes