Skip to content

Commit

Permalink
Basic prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
Infocatcher committed Oct 5, 2017
1 parent 50a8df2 commit fb833d8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fb833d8

Please sign in to comment.