From 26c5968b6475a22c68d16fee51b900847497032d Mon Sep 17 00:00:00 2001 From: kkapsner Date: Sat, 23 Sep 2017 23:47:44 +0200 Subject: [PATCH] Fixed bug that the update of the lists sometimes did not use the new value but the old one. --- lib/lists.js | 26 ++++++++++++++------------ lib/require.js | 6 ++++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/lists.js b/lib/lists.js index a9c2502..984cecc 100644 --- a/lib/lists.js +++ b/lib/lists.js @@ -67,24 +67,26 @@ black: [] }; - function updateList(type){ + function updateList(type, value){ "use strict"; - - lists[type] = getDomainRegExpList(prefs[type + "List"]); + if (typeof value === "undefined"){ + value = prefs[type + "List"]; + } + lists[type] = getDomainRegExpList(value); } Object.keys(lists).forEach(function(type){ "use strict"; - preferences.on(type + "List", function(){ - updateList(type); + preferences.on(type + "List", function(value){ + updateList(type, value); }); - updateList(type); + updateList(type, prefs[type + "List"]); }); - function updateStackList(){ + function updateStackList(value){ var list; try { - var data = JSON.parse(prefs.stackList); + var data = JSON.parse(value); if (!Array.isArray(data)){ data = [data]; } @@ -103,10 +105,10 @@ lists.stack = list; } lists.stack = []; - preferences.on("stackList", function(){ - updateStackList(); + preferences.on("stackList", function(value){ + updateStackList(value); }); - updateStackList(); + updateStackList(prefs.stackList); scope.get = function getList(type){ "use strict"; @@ -127,6 +129,6 @@ updateList("white"); updateList("ignore"); updateList("black"); - updateStackList(); + updateStackList(prefs.stackList); }; }()); \ No newline at end of file diff --git a/lib/require.js b/lib/require.js index 9646cb3..55a64e7 100644 --- a/lib/require.js +++ b/lib/require.js @@ -16,7 +16,7 @@ function require(module){ browser.storage.onChanged.addListener(function(changes, area){ if (area === "local"){ if (changes.hasOwnProperty(key)){ - callback(); + callback(changes[key].newValue); } } }); @@ -37,4 +37,6 @@ function require(module){ } console.error("Not able to get non relative modules!", module); return undefined; -} \ No newline at end of file +} + +window.scope.require = require; \ No newline at end of file