2017-07-27 19:14:04 +02:00
|
|
|
/* 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/. */
|
2017-10-03 15:35:31 +02:00
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const logging = require("./logging");
|
2017-11-07 00:36:44 +01:00
|
|
|
logging.setPrefix("options page");
|
|
|
|
|
|
|
|
const optionsGui = require("./optionsGui");
|
|
|
|
const settings = require("./settings");
|
|
|
|
const settingsDisplay = require("./settingsDisplay");
|
2017-10-03 15:35:31 +02:00
|
|
|
|
2017-11-07 00:36:44 +01:00
|
|
|
var callbacks = {
|
|
|
|
showReleaseNotes: function(){
|
|
|
|
logging.verbose("open release notes");
|
|
|
|
window.open("../releaseNotes.txt", "_blank");
|
|
|
|
},
|
|
|
|
clearPersistentRnd: function(){
|
|
|
|
logging.message("clear persistent rnd storage");
|
|
|
|
logging.notice("empty storage");
|
|
|
|
settings.persistentRndStorage = "";
|
|
|
|
logging.notice("send message to main script");
|
|
|
|
browser.runtime.sendMessage({"canvasBlocker-clear-domain-rnd": true});
|
2017-11-14 01:07:27 +01:00
|
|
|
},
|
|
|
|
exportSettings: function(){
|
|
|
|
logging.verbose("open settings export");
|
|
|
|
window.open("export.html", "_blank");
|
2017-11-22 14:14:33 +01:00
|
|
|
},
|
|
|
|
resetSettings: function(){
|
|
|
|
if (window.confirm(browser.i18n.getMessage("resetSettings_confirm"))){
|
|
|
|
browser.storage.local.clear();
|
|
|
|
}
|
2017-06-25 22:11:28 +02:00
|
|
|
}
|
2017-11-07 00:36:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
var table = document.createElement("table");
|
2017-11-11 23:34:59 +01:00
|
|
|
table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions";
|
|
|
|
settings.on("displayDescriptions", function(){
|
|
|
|
table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions";
|
|
|
|
});
|
|
|
|
|
2017-11-07 00:36:44 +01:00
|
|
|
document.body.appendChild(table);
|
|
|
|
settingsDisplay.forEach(function(display){
|
|
|
|
var setting = settings.getDefinition(display.name);
|
|
|
|
if (!setting){
|
2017-11-08 17:46:41 +01:00
|
|
|
if (display.inputs){
|
|
|
|
setting = {
|
|
|
|
name: display.name,
|
|
|
|
inputs: display.inputs.map(settings.getDefinition)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (callbacks[display.name]){
|
2017-11-07 00:36:44 +01:00
|
|
|
setting = {
|
|
|
|
name: display.name,
|
|
|
|
action: callbacks[display.name]
|
|
|
|
};
|
2017-10-03 15:35:31 +02:00
|
|
|
}
|
2017-11-07 00:36:44 +01:00
|
|
|
}
|
|
|
|
if (setting){
|
|
|
|
var row = optionsGui.createSettingRow(setting);
|
|
|
|
table.appendChild(row);
|
|
|
|
if (display.displayDependencies){
|
|
|
|
var displayDependencies = display.displayDependencies;
|
|
|
|
displayDependencies = Array.isArray(displayDependencies)?
|
|
|
|
displayDependencies:
|
|
|
|
[displayDependencies];
|
|
|
|
var computeDependencies = function(){
|
|
|
|
logging.verbose("evaluate display dependencies for", setting);
|
2017-10-03 15:35:31 +02:00
|
|
|
row.classList[(
|
2017-11-07 00:36:44 +01:00
|
|
|
displayDependencies.some(function(displayDependency){
|
2017-10-03 15:35:31 +02:00
|
|
|
return Object.keys(displayDependency).every(function(key){
|
|
|
|
return displayDependency[key].indexOf(settings[key]) !== -1;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
)? "remove": "add"]("hidden");
|
2017-11-07 00:36:44 +01:00
|
|
|
};
|
|
|
|
computeDependencies();
|
|
|
|
displayDependencies.forEach(function(displayDependency){
|
|
|
|
Object.keys(displayDependency).forEach(function(name){
|
|
|
|
settings.on(name, computeDependencies);
|
|
|
|
});
|
2017-10-03 15:35:31 +02:00
|
|
|
});
|
|
|
|
}
|
2017-11-07 00:36:44 +01:00
|
|
|
}
|
2017-06-25 22:11:28 +02:00
|
|
|
});
|
2017-10-03 19:51:03 +02:00
|
|
|
}());
|