1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-08 20:54:49 +01:00

Added sections to options list

This commit is contained in:
kkapsner 2017-12-24 21:52:44 +01:00
parent a85ea32a74
commit 6c363c076b
5 changed files with 175 additions and 54 deletions

View File

@ -17,6 +17,32 @@
"description": "" "description": ""
}, },
"section_asking": {
"message": "Nachfragen",
"description": ""
},
"section_faking": {
"message": "Vortäuschen",
"description": ""
},
"section_notifications": {
"message": "Benachrichtigungen",
"description": ""
},
"section_lists": {
"message": "Listen",
"description": ""
},
"section_misc": {
"message": "Gemischtes",
"description": ""
},
"section_settings": {
"message": "Einstellungen",
"description": ""
},
"displayAdvancedSettings_title": { "displayAdvancedSettings_title": {
"message": "Expertenmodus", "message": "Expertenmodus",
"description": "" "description": ""

View File

@ -17,6 +17,32 @@
"description": "" "description": ""
}, },
"section_asking": {
"message": "Asking",
"description": ""
},
"section_faking": {
"message": "Faking",
"description": ""
},
"section_notifications": {
"message": "Notifications",
"description": ""
},
"section_lists": {
"message": "Lists",
"description": ""
},
"section_misc": {
"message": "Misc",
"description": ""
},
"section_settings": {
"message": "Settings",
"description": ""
},
"displayAdvancedSettings_title": { "displayAdvancedSettings_title": {
"message": "Expert mode", "message": "Expert mode",
"description": "" "description": ""

View File

@ -10,10 +10,22 @@
vertical-align: top; vertical-align: top;
} }
.settings .settingRow.hidden { .settings .hidden {
display: none; display: none;
} }
.settings td, .settings th {
margin: 0;
padding: 0;
}
.settings .section h2 {
border: 1px #c1c1c1 solid;
border-radius: 0.5em ;
padding: 0.2em 0.5em;
margin: 0.7em 1px 0.2em;
}
.settings .settingRow .content { .settings .settingRow .content {
overflow: visible; overflow: visible;
padding: 0.5em 0; padding: 0.5em 0;
@ -21,6 +33,17 @@
position: relative; position: relative;
} }
.settings .settingRow td:first-child .content {
margin-left: 0.6em;
}
.settings .settingRow td:last-child .content {
margin-right: 0.6em;
}
.settings .section + .settingRow .content {
border-top: 0 solid black;
}
.settings.hideDescriptions .settingRow .info { .settings.hideDescriptions .settingRow .info {
margin: 0 0.5em; margin: 0 0.5em;
border-radius: 100%; border-radius: 100%;

View File

@ -39,48 +39,88 @@
settings.on("displayDescriptions", function(){ settings.on("displayDescriptions", function(){
table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions"; table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions";
}); });
document.body.appendChild(table); document.body.appendChild(table);
settingsDisplay.forEach(function(display){
var setting = settings.getDefinition(display.name); let lastSection = null;
if (!setting){ let addSection = function addSection(name){
if (display.inputs){ let body = document.createElement("tbody");
setting = { if (name){
name: display.name, let row = document.createElement("tr");
inputs: display.inputs.map(settings.getDefinition) row.className = "section";
}; let cell = document.createElement("td");
} cell.colSpan = 2;
else if (callbacks[display.name]){ row.appendChild(cell);
setting = { let heading = document.createElement("h2");
name: display.name, heading.textContent = browser.i18n.getMessage("section_" + name);
action: callbacks[display.name] cell.appendChild(heading);
}; body.appendChild(row);
}
} }
if (setting){ table.appendChild(body);
var row = optionsGui.createSettingRow(setting); let rows = [];
table.appendChild(row); let section = {
if (display.displayDependencies){ addRow: function(row){
var displayDependencies = display.displayDependencies; rows.push(row);
displayDependencies = Array.isArray(displayDependencies)? body.appendChild(row);
displayDependencies: },
[displayDependencies]; updateDisplay: function(){
var computeDependencies = function(){ body.classList[(
logging.verbose("evaluate display dependencies for", setting); rows.some(function(row){
row.classList[( return !row.classList.contains("hidden");
displayDependencies.some(function(displayDependency){ })
return Object.keys(displayDependency).every(function(key){ )? "remove": "add"]("hidden");
return displayDependency[key].indexOf(settings[key]) !== -1; }
}); };
}) lastSection = section;
)? "remove": "add"]("hidden"); };
}; addSection();
computeDependencies();
displayDependencies.forEach(function(displayDependency){ settingsDisplay.forEach(function(display){
Object.keys(displayDependency).forEach(function(name){ if (typeof display === "string"){
settings.on(name, computeDependencies); addSection(display);
}
else {
var setting = settings.getDefinition(display.name);
if (!setting){
if (display.inputs){
setting = {
name: display.name,
inputs: display.inputs.map(settings.getDefinition)
};
}
else if (callbacks[display.name]){
setting = {
name: display.name,
action: callbacks[display.name]
};
}
}
if (setting){
var row = optionsGui.createSettingRow(setting);
let section = lastSection;
section.addRow(row);
if (display.displayDependencies){
var displayDependencies = display.displayDependencies;
displayDependencies = Array.isArray(displayDependencies)?
displayDependencies:
[displayDependencies];
var computeDependencies = function(){
logging.verbose("evaluate display dependencies for", setting);
row.classList[(
displayDependencies.some(function(displayDependency){
return Object.keys(displayDependency).every(function(key){
return displayDependency[key].indexOf(settings[key]) !== -1;
});
})
)? "remove": "add"]("hidden");
section.updateDisplay();
};
computeDependencies();
displayDependencies.forEach(function(displayDependency){
Object.keys(displayDependency).forEach(function(name){
settings.on(name, computeDependencies);
});
}); });
}); }
} }
} }
}); });

View File

@ -13,20 +13,7 @@
{ {
"name": "blockMode" "name": "blockMode"
}, },
{ "asking",
"name": "whiteList",
"displayDependencies": {
"blockMode": ["blockReadout", "fakeReadout", "fakeInput", "askReadout", "block", "ask"],
"displayAdvancedSettings": [true]
}
},
{
"name": "blackList",
"displayDependencies": {
"blockMode": ["blockReadout", "fakeReadout", "fakeInput", "askReadout", "ask", "allow"],
"displayAdvancedSettings": [true]
}
},
{ {
"name": "askOnlyOnce", "name": "askOnlyOnce",
"displayDependencies": { "displayDependencies": {
@ -40,6 +27,7 @@
"displayAdvancedSettings": [true] "displayAdvancedSettings": [true]
} }
}, },
"faking",
{ {
"name": "minFakeSize", "name": "minFakeSize",
"displayDependencies": [ "displayDependencies": [
@ -187,6 +175,7 @@
} }
] ]
}, },
"notifications",
{ {
"name": "showNotifications", "name": "showNotifications",
"displayDependencies": [ "displayDependencies": [
@ -252,6 +241,7 @@
} }
] ]
}, },
"lists",
{ {
"name": "enableStackList", "name": "enableStackList",
"displayDependencies": { "displayDependencies": {
@ -267,6 +257,21 @@
} }
}, },
{
"name": "whiteList",
"displayDependencies": {
"blockMode": ["blockReadout", "fakeReadout", "fakeInput", "askReadout", "block", "ask"],
"displayAdvancedSettings": [true]
}
},
{
"name": "blackList",
"displayDependencies": {
"blockMode": ["blockReadout", "fakeReadout", "fakeInput", "askReadout", "ask", "allow"],
"displayAdvancedSettings": [true]
}
},
"misc",
{ {
"name": "showReleaseNotes" "name": "showReleaseNotes"
}, },
@ -276,6 +281,7 @@
"displayAdvancedSettings": [true] "displayAdvancedSettings": [true]
} }
}, },
"settings",
{ {
"name": "exportSettings", "name": "exportSettings",
"displayDependencies": { "displayDependencies": {