From 1aebba1ccbc163656720f40b48ffb2e7c2d03ef5 Mon Sep 17 00:00:00 2001 From: Utopiah Date: Wed, 5 Aug 2026 15:15:20 +0200 Subject: [PATCH] options --- kbd.js | 27 +++++++++++++++++++++++++-- options.html | 22 ++++++++++++++++++++++ options.js | 25 +++++++++++++++++++++++++ package_and_share | 2 +- 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 options.html create mode 100644 options.js 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 @@ + + + + + + + + + +

PIM

+
+ + + + +
+ + + + + + diff --git a/options.js b/options.js new file mode 100644 index 0000000..9ae0ac0 --- /dev/null +++ b/options.js @@ -0,0 +1,25 @@ +function saveOptions(e) { + e.preventDefault(); + browser.storage.local.set({ + URL: document.querySelector("#URL").value, + author: document.querySelector("#author").value, + password: document.querySelector("#password").value + }); +} + +function restoreOptions() { + + function setCurrentChoice(result) { + document.querySelector("#password").value = result.color || ""; + } + + function onError(error) { + console.log(`Error: ${error}`); + } + + var getting = browser.storage.local.get("color"); + getting.then(setCurrentChoice, onError); +} + +document.addEventListener("DOMContentLoaded", restoreOptions); +document.querySelector("form").addEventListener("submit", saveOptions); diff --git a/package_and_share b/package_and_share index f86afdd..bfbd552 100755 --- a/package_and_share +++ b/package_and_share @@ -1,5 +1,5 @@ #!/bin/bash sed "s/\"version.*/\"version\": \"$(date +%s)\",/" -i manifest.json -zip -r0 kbd.xpi manifest.json kbd.js options.html icons/ +zip -r0 kbd.xpi manifest.json kbd.js options.html options.js icons/ kdeconnect-cli -n Pixel --share kbd.xpi