mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Centralized settings management
This commit is contained in:
parent
18df3f97fe
commit
2193313980
24 changed files with 917 additions and 912 deletions
25
lib/lists.js
25
lib/lists.js
|
@ -15,8 +15,7 @@
|
|||
scope = window.scope.lists;
|
||||
}
|
||||
|
||||
var preferences = require("sdk/simple-prefs");
|
||||
var prefs = preferences.prefs;
|
||||
var settings = require("./settings");
|
||||
|
||||
|
||||
function getDomainRegExpList(domainList){
|
||||
|
@ -66,15 +65,15 @@
|
|||
|
||||
function updateList(type, value){
|
||||
if (typeof value === "undefined"){
|
||||
value = prefs[type + "List"];
|
||||
value = settings[type + "List"];
|
||||
}
|
||||
lists[type] = getDomainRegExpList(value);
|
||||
}
|
||||
Object.keys(lists).forEach(function(type){
|
||||
preferences.on(type + "List", function(value){
|
||||
updateList(type, value);
|
||||
settings.on(type + "List", function({newValue}){
|
||||
updateList(type, newValue);
|
||||
});
|
||||
updateList(type, prefs[type + "List"]);
|
||||
updateList(type, settings[type + "List"]);
|
||||
});
|
||||
|
||||
function updateStackList(value){
|
||||
|
@ -99,19 +98,16 @@
|
|||
lists.stack = list;
|
||||
}
|
||||
lists.stack = [];
|
||||
preferences.on("stackList", function(value){
|
||||
updateStackList(value);
|
||||
settings.on("stackList", function({newValue}){
|
||||
updateStackList(newValue);
|
||||
});
|
||||
updateStackList(prefs.stackList);
|
||||
updateStackList(settings.stackList);
|
||||
|
||||
scope.get = function getList(type){
|
||||
return lists[type];
|
||||
};
|
||||
scope.appendTo = function appendToList(type, entry){
|
||||
prefs[type + "List"] += (prefs[type + "List"]? ",": "") + entry;
|
||||
var obj = {};
|
||||
obj[type + "List"] = prefs[type + "List"];
|
||||
browser.storage.local.set(obj);
|
||||
settings[type + "List"] += (settings[type + "List"]? ",": "") + entry;
|
||||
updateList(type);
|
||||
};
|
||||
scope.update = updateList;
|
||||
|
@ -119,6 +115,7 @@
|
|||
updateList("white");
|
||||
updateList("ignore");
|
||||
updateList("black");
|
||||
updateStackList(prefs.stackList);
|
||||
updateStackList(settings.stackList);
|
||||
};
|
||||
settings.onloaded(scope.updateAll);
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue