diff --git a/kbd.js b/kbd.js index 2e1f690..e53a93e 100644 --- a/kbd.js +++ b/kbd.js @@ -1,6 +1,22 @@ console.log('extension loaded kbd'); let blocked = false +let gettingItem + +if (typeof browser === 'undefined'){ + console.warn('running without extension context, will miss APIs') +} else { + gettingItem = browser.storage.local.get() + gettingItem.then(onGot, onError) +} + +function onGot(items){ + console.log( items ) +} + +function onError(error) { + console.log(`Error: ${error}`) +} let key, modifiers = [] document.addEventListener("keydown", function(event) { @@ -37,13 +53,20 @@ let userActions = [ { key: 'x', action: 'autoscroll()'}, { key: 'b', action: 'history.back()'}, { key: 'a', action: 'addWiki()'}, + { key: 'n', action: 'firstTab()'}, { key: 'r', action: 'window.location.reload()'}, { key: 'h', action: 'alert("r to reload, h for help, etc")'}, - // could have example with modifier, e.g. Ctrl or Shift - // or multiple modifiers { key: 'h', mods: ['Alt'], action: 'alert("modified help!")'}, ] +function firstTab(){ + console.log( browser, browser.tabs ) + // does not work, somehow browser.tabs remain undefined even with permissions accepted + browser.tabs.query({currentWindow: true}).then( (tabs,n) => { + if (n==0) browser.tabs.update(tab.id, { active: true }) + }) +} + // from https://gist.github.com/Utopiah/525718c8a60ee2d9e25d7724e9dbb355 const month = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ][new Date().getMonth()]; const year = new Date().getFullYear(); diff --git a/options.html b/options.html new file mode 100644 index 0000000..10669d5 --- /dev/null +++ b/options.html @@ -0,0 +1,22 @@ + + + +
+ + + + + +