From 1629d7e468735a96d3c0a2cc6c8a2d42881f0390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Thu, 10 Aug 2023 13:58:28 +0200 Subject: [PATCH] feat: add context menu to open npubs --- src/extension/background-script/index.ts | 17 ++++++++++++++++- src/manifest.json | 6 ++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index 6cc781c840..af7a548433 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -86,6 +86,13 @@ const handleInstalled = (details: { reason: string }) => { console.info("Alby was recently updated"); isRecentlyUpdated = true; } + + browser.contextMenus.create({ + id: "test", + title: "Open on nostr", + type: "normal", + contexts: ["selection"], + }); }; // listen to calls from the content script and calls the actions through the router @@ -138,7 +145,15 @@ browser.tabs.onUpdated.addListener(extractLightningData); // When we subscribe to that event asynchronously in the init() function it is too late and we miss the event. browser.runtime.onInstalled.addListener(handleInstalled); -async function init() { +browser.contextMenus.onClicked.addListener(function (info) { + // TODO check if npub + browser.tabs.create({ + active: true, + url: `https://snort.social/${info.selectionText}`, + }); +}); + +async function init(): Promise { console.info("Loading background script"); await state.getState().init(); diff --git a/src/manifest.json b/src/manifest.json index 30164c12da..510b821405 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -40,7 +40,8 @@ "tabs", "unlimitedStorage", "*://*/*", - "identity" + "identity", + "contextMenus" ], "__chrome__permissions": [ "activeTab", @@ -49,7 +50,8 @@ "storage", "tabs", "unlimitedStorage", - "identity" + "identity", + "contextMenus" ], "__chrome__host_permissions": ["*://*/*"], "content_security_policy": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'",