mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Added export and import for settings
This commit is contained in:
parent
41d9b7073f
commit
d531abb2de
@ -487,5 +487,14 @@
|
||||
"logLevel_options.100": {
|
||||
"message": "ausführlich",
|
||||
"description": ""
|
||||
},
|
||||
|
||||
"exportSettings_title": {
|
||||
"message": "Einstellungen exportieren",
|
||||
"description": ""
|
||||
},
|
||||
"exportSettings_label": {
|
||||
"message": "Anzeigen",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
@ -491,5 +491,14 @@
|
||||
"logLevel_options.100": {
|
||||
"message": "verbose",
|
||||
"description": ""
|
||||
},
|
||||
|
||||
"exportSettings_title": {
|
||||
"message": "Export settings",
|
||||
"description": ""
|
||||
},
|
||||
"exportSettings_label": {
|
||||
"message": "Show",
|
||||
"description": ""
|
||||
}
|
||||
}
|
@ -44,22 +44,41 @@
|
||||
settingDefinition.on = function on(callback){
|
||||
scope.on(name, callback);
|
||||
};
|
||||
settingDefinition.get = function getValue(){
|
||||
return settings[name];
|
||||
};
|
||||
settingDefinition.set = function setValue(newValue){
|
||||
settingDefinition.invalid = function invalid(newValue){
|
||||
if (settingDefinition.fixed){
|
||||
logging.warning("Trying to set the fixed setting", name, ":", newValue);
|
||||
return "fixed";
|
||||
}
|
||||
else if ((typeof newValue) !== (typeof settingDefinition.defaultValue)){
|
||||
logging.warning("Wrong type provided for setting", name, ":", newValue);
|
||||
return "wrongType";
|
||||
}
|
||||
else if (
|
||||
settingDefinition.options &&
|
||||
!settingDefinition.options.includes(newValue)
|
||||
){
|
||||
return "noOption";
|
||||
}
|
||||
return false;
|
||||
};
|
||||
settingDefinition.get = function getValue(){
|
||||
return settings[name];
|
||||
};
|
||||
settingDefinition.set = function setValue(newValue){
|
||||
logging.verbose("New value for %s:", name, newValue);
|
||||
var invalid = settingDefinition.invalid(newValue);
|
||||
if (invalid){
|
||||
if (invalid === "fixed"){
|
||||
logging.warning("Trying to set the fixed setting", name, ":", newValue);
|
||||
}
|
||||
else if (invalid === "wrongType"){
|
||||
logging.warning("Wrong type provided for setting", name, ":", newValue);
|
||||
}
|
||||
else if (invalid === "noOption"){
|
||||
logging.warning("Provided value outside specified options for ", name, ":", newValue);
|
||||
}
|
||||
else {
|
||||
logging.warning("Unknown invalid state:", invalid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
settings[name] = newValue;
|
||||
if (!settingDefinition.transient){
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "CanvasBlocker",
|
||||
"description": "__MSG_addon_description__",
|
||||
"version": "0.4.1-Development",
|
||||
"version": "0.4.2-Development",
|
||||
"icons": {
|
||||
"48": "icons/icon.svg",
|
||||
"96": "icons/icon.svg"
|
||||
@ -66,7 +66,7 @@
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "CanvasBlocker@kkapsner.de",
|
||||
"strict_min_version": "52.4.1"
|
||||
"strict_min_version": "52.0"
|
||||
}
|
||||
},
|
||||
"default_locale": "en",
|
||||
|
13
options/export.css
Normal file
13
options/export.css
Normal file
@ -0,0 +1,13 @@
|
||||
html, body {
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#settings {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
height: 95%;
|
||||
}
|
||||
#settings.invalid {
|
||||
background-color: pink;
|
||||
}
|
16
options/export.html
Normal file
16
options/export.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CanvasBlocker Export Settings</title>
|
||||
<link href="export.css" rel="stylesheet" type="text/css">
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
<textarea id="settings"></textarea>
|
||||
<script src="../lib/require.js"></script>
|
||||
<script src="../lib/settingDefinitions.js"></script>
|
||||
<script src="../lib/settings.js"></script>
|
||||
<script src="../lib/logging.js"></script>
|
||||
<script src="export.js"></script>
|
||||
</body>
|
||||
</html>
|
57
options/export.js
Normal file
57
options/export.js
Normal file
@ -0,0 +1,57 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
const settings = require("./settings");
|
||||
const logging = require("./logging");
|
||||
const input = document.getElementById("settings");
|
||||
settings.onloaded(function(){
|
||||
var data = {};
|
||||
settings.forEach(function(def){
|
||||
data[def.name] = def.get();
|
||||
});
|
||||
input.value = JSON.stringify(data, null, "\t");
|
||||
|
||||
input.addEventListener("input", function(){
|
||||
try {
|
||||
var newSettings = JSON.parse(this.value);
|
||||
var isValid = true;
|
||||
|
||||
|
||||
Object.entries(newSettings).forEach(function(entry){
|
||||
const [name, value] = entry;
|
||||
const def = settings.getDefinition(name);
|
||||
if (!def){
|
||||
logging.warning("Setting %s not known.");
|
||||
isValid = false;
|
||||
}
|
||||
else if (def.get() !== value){
|
||||
const invalid = def.invalid(value);
|
||||
if (invalid){
|
||||
isValid = false;
|
||||
logging.warning("Invalid setting for %s:", name, value, invalid);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isValid){
|
||||
this.classList.remove("invalid");
|
||||
Object.entries(newSettings).forEach(function(entry){
|
||||
const [name, value] = entry;
|
||||
if (settings[name] !== value){
|
||||
settings[name] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.classList.add("invalid");
|
||||
}
|
||||
}
|
||||
catch (e){
|
||||
logging.warning("Invalid JSON:", e);
|
||||
this.classList.add("invalid");
|
||||
}
|
||||
});
|
||||
});
|
||||
}());
|
@ -22,6 +22,10 @@
|
||||
settings.persistentRndStorage = "";
|
||||
logging.notice("send message to main script");
|
||||
browser.runtime.sendMessage({"canvasBlocker-clear-domain-rnd": true});
|
||||
},
|
||||
exportSettings: function(){
|
||||
logging.verbose("open settings export");
|
||||
window.open("export.html", "_blank");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -257,6 +257,12 @@
|
||||
"displayDependencies": {
|
||||
"displayAdvancedSettings": [true]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "exportSettings",
|
||||
"displayDependencies": {
|
||||
"displayAdvancedSettings": [true]
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
Version 0.4.2
|
||||
new features:
|
||||
- added settings export and import
|
||||
|
||||
fixes:
|
||||
- settings are sometimes not fast enough loaded
|
||||
|
||||
Version 0.4.1:
|
||||
changes:
|
||||
- improved design of the page action display
|
||||
|
Loading…
x
Reference in New Issue
Block a user