diff --git a/background.js b/background.js index 5289408..42e65b6 100644 --- a/background.js +++ b/background.js @@ -1,5 +1,23 @@ const LOG_PREFIX = "[Private Tab WE] "; +var prefs = { + debug: true, + loadInBackground: false +}; +browser.storage.local.get().then(function(o) { + browser.storage.onChanged.addListener(function(changes, area) { + if(area == "local") for(var key in changes) + prefs[key] = changes[key].newValue; + }); + Object.assign(prefs, o); + + for(var key in o) + return; // Prefs already saved + setTimeout(function() { // Pseudo async + browser.storage.local.set(prefs); + }, 5000); +}, _err); + browser.contextMenus.create({ id: "openInTab", title: browser.i18n.getMessage("openInNewPrivateTab"), @@ -22,8 +40,7 @@ browser.contextMenus.onClicked.addListener(function(info, tab) { url: info.linkUrl, cookieStoreId: sId, openerTabId: tab.id, - //~ todo: add options - active: true, + active: !prefs.loadInBackground, index: tab.index + 1 }; try { @@ -169,8 +186,8 @@ function ts() { return d.toTimeString().replace(/^.*\d+:(\d+:\d+).*$/, "$1") + ":" + "000".substr(("" + ms).length) + ms + " "; } function _log(s) { - //if(_dbg) - console.log(LOG_PREFIX + ts() + s); + if(prefs.debug) + console.log(LOG_PREFIX + ts() + s); } function _err(s) { console.error(LOG_PREFIX + ts() + s);