1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-03 20:16:33 +02:00

Added logging lib with setting to control log level.

This commit is contained in:
kkapsner 2017-07-27 19:14:04 +02:00
parent 65ad3a5814
commit 9715eb09d2
13 changed files with 299 additions and 108 deletions

View file

@ -220,6 +220,38 @@ document.body.appendChild(table);
"title": "Release notes",
"type": "control",
"label": "Show"
},
{
"name": "logLevel",
"title": "logging level",
"type": "menulist",
"value": 1,
"options": [
{
"value": 0,
"label": "none"
},
{
"value": 1,
"label": "error"
},
{
"value": 25,
"label": "warning"
},
{
"value": 50,
"label": "message"
},
{
"value": 75,
"label": "notice"
},
{
"value": 100,
"label": "verbose"
}
]
}
].forEach(function(pref){
var html = '<td><div class="content"><span class="title">__MSG_' + pref.name + '_title__</span><div class="description">__MSG_' + pref.name + '_description__</div></div></td><td><div class="content">';
@ -235,9 +267,9 @@ document.body.appendChild(table);
html += '<input type="checkbox" style="display: inline"' + inputAttributes + (pref.value? ' checked="checked"': "") + '>';
break;
case "menulist":
html += '<select' + inputAttributes + '>' +
html += '<select' + inputAttributes + 'data-type="' + (typeof pref.value) + '">' +
pref.options.map(function(option){
if (option.value){
if (option.value !== ""){
return '<option value="' + option.value + '"' + (option.value === pref.value? " selected": "") + '>__MSG_' + pref.name + '_options.' + option.label + '__</option>';
}
else {
@ -250,13 +282,13 @@ document.body.appendChild(table);
html += '<button' + inputAttributes + '">__MSG_' + pref.name + '_label__</button>';
break;
default:
console.log("Unknown preference type: " + pref.type);
logging.warning("Unknown preference type: " + pref.type);
}
html += "</div></td>";
var tr = document.createElement("tr");
tr.setting = pref;
tr.className = "settingRow";
tr.innerHTML = html;
console.log(html);
logging.verbose(html);
table.appendChild(tr);
});

View file

@ -7,6 +7,7 @@
</head>
<body>
<script src="../lib/defaultSettings.js"></script>
<script src="../lib/logging.js"></script>
<script src="buildPrefInputs.js"></script>
<script src="options.js"></script>
</body>

View file

@ -1,7 +1,13 @@
/* jslint moz: true */
/* 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/. */
browser.storage.local.get().then(function(data){
Object.keys(data).forEach(function(key){
settings[key] = data[key];
});
settings.isStillDefault = false;
logging.clearQueue();
return settings;
}).then(function(settings){
function traverse(node, func){
@ -10,6 +16,7 @@ browser.storage.local.get().then(function(data){
}
// getting the translation of all the messages
message("transate all messages");
traverse(document.body, function(node){
if (node.nodeType == 3){
var lines = node.nodeValue.replace(/\b__MSG_(.+)__\b/g, function(m, key){
@ -28,12 +35,14 @@ browser.storage.local.get().then(function(data){
}
});
message("register events to store changes in local storage");
Array.from(document.querySelectorAll("input.setting, select.setting")).forEach(function(input){
var storageName = input.dataset.storageName;
if (input.type === "checkbox"){
input.checked = settings[storageName];
input.addEventListener("click", function(){
message("changed setting", storageName, ":", this.checked);
var value = this.checked;
var obj = {};
obj[storageName] = value;
@ -44,9 +53,10 @@ browser.storage.local.get().then(function(data){
input.addEventListener("change", function(){
var value = this.value;
if (this.type === "number"){
if (this.type === "number" || this.dataset.type === "number"){
value = parseFloat(value);
}
message("changed setting", storageName, ":", value);
var obj = {};
obj[storageName] = value;
browser.storage.local.set(obj);
@ -56,6 +66,7 @@ browser.storage.local.get().then(function(data){
var callbacks = {
showReleaseNotes: function(){
verbose("open release notes");
window.open("../releaseNotes.txt", "_blank");
// would be nicer but is not supported in fennec
// browser.windows.create({
@ -64,7 +75,10 @@ browser.storage.local.get().then(function(data){
// });
},
clearPersistentRnd: function(){
message("clear persistent rnd storage");
notice("empty storage");
browser.storage.local.set({persistentRndStorage: ""});
notice("send message to main script");
browser.runtime.sendMessage({"canvasBlocker-clear-domain-rnd": true});
}
};
@ -78,13 +92,14 @@ browser.storage.local.get().then(function(data){
});
function updateDisplay(){
notice("update display");
document.querySelectorAll("tr.settingRow").forEach(function(row){
verbose("evaluate display dependencies for", row.setting);
var displayDependencies = row.setting.displayDependencies;
if (displayDependencies){
row.classList[(
(Array.isArray(displayDependencies)? displayDependencies: [displayDependencies]).some(function(displayDependency){
return Object.keys(displayDependency).every(function(key){
console.log(key, displayDependency[key], settings[key]);
return displayDependency[key].indexOf(settings[key]) !== -1;
});
})