1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-18 09:28:52 +01:00

Fixed: options page did not update and checkboxes were not displayed.

This commit is contained in:
kkapsner 2017-07-02 12:18:20 +02:00
parent 584f178ff7
commit b6dd2ff011
3 changed files with 51 additions and 31 deletions

View File

@ -109,12 +109,12 @@ document.body.appendChild(table);
"type": "bool", "type": "bool",
"value": true "value": true
}, },
{ // {
"name": "notificationDisplayTime", // "name": "notificationDisplayTime",
"title": "notification display time", // "title": "notification display time",
"type": "integer", // "type": "integer",
"value": 30 // "value": 30
}, // },
{ {
"name": "ignoreList", "name": "ignoreList",
"title": "Ignore list", "title": "Ignore list",
@ -161,7 +161,7 @@ document.body.appendChild(table);
html += '<input type="text"' + inputAttributes + ' value="' + pref.value + '">'; html += '<input type="text"' + inputAttributes + ' value="' + pref.value + '">';
break; break;
case "bool": case "bool":
html += '<input type="checkbox"' + inputAttributes + (pref.value? ' checked="checked"': "") + '>'; html += '<input type="checkbox" style="display: inline"' + inputAttributes + (pref.value? ' checked="checked"': "") + '>';
break; break;
case "menulist": case "menulist":
html += '<select' + inputAttributes + '>' + html += '<select' + inputAttributes + '>' +

View File

@ -3,6 +3,7 @@
<head> <head>
<title>CanvasBlocker Settings</title> <title>CanvasBlocker Settings</title>
<link href="options.css" rel="stylesheet" type="text/css"> <link href="options.css" rel="stylesheet" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head> </head>
<body> <body>
<script src="buildPrefInputs.js"></script> <script src="buildPrefInputs.js"></script>

View File

@ -20,30 +20,39 @@
Array.from(document.querySelectorAll("input.setting, select.setting")).forEach(function(input){ Array.from(document.querySelectorAll("input.setting, select.setting")).forEach(function(input){
var storageName = input.dataset.storageName; var storageName = input.dataset.storageName;
browser.storage.local.get(storageName).then(function(value){ if (input.type === "checkbox"){
// console.log(storageName, "got storage value", value); browser.storage.local.get(storageName).then(function(value){
if (value.hasOwnProperty(storageName)){ // console.log(storageName, "got storage value", value);
input.value = value[storageName]; if (value.hasOwnProperty(storageName)){
} input.checked = value[storageName];
}); }
});
input.addEventListener("change", function(){ input.addEventListener("click", function(){
var value; var value = this.checked;
if (this.type === "checkbox"){ var obj = {};
value = this.checked; obj[storageName] = value;
} browser.storage.local.set(obj);
else { });}
value = this.value; else {
} browser.storage.local.get(storageName).then(function(value){
var obj = {}; // console.log(storageName, "got storage value", value);
obj[storageName] = value; if (value.hasOwnProperty(storageName)){
browser.storage.local.set(obj); input.value = value[storageName];
}); }
});
input.addEventListener("change", function(){
var value = this.value;
var obj = {};
obj[storageName] = value;
browser.storage.local.set(obj);
});
}
}); });
var callbacks = { var callbacks = {
showReleaseNotes: function(){ showReleaseNotes: function(){
console.log("sdsdsdsd");
window.open("../releaseNotes.txt", "_blank"); window.open("../releaseNotes.txt", "_blank");
}, },
clearPersistentRnd: function(){ clearPersistentRnd: function(){
@ -60,9 +69,19 @@
}); });
}); });
browser.storage.onChanged.addListener(function(data){ browser.storage.onChanged.addListener(function(change, area){
Object.keys(data).forEach(function(storageName){ if (area === "local"){
Object.keys(change).forEach(function(key){
}); var input = document.querySelector(".setting[data-storage-name=" + key + "]");
if (input){
if (input.type === "checkbox"){
input.checked = change[key].newValue;
}
else {
input.value = change[key].newValue;
}
}
});
}
}); });
}()); }());