From 89d6b9e05c6fee345b8febd9bdcdfab11095e258 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 18 Oct 2022 23:45:10 -0700 Subject: [PATCH] Shift-click pastes clipboard to a task --- background.js | 16 ++++++++++++++++ manifest.json | 1 + 2 files changed, 17 insertions(+) diff --git a/background.js b/background.js index 0eb248e..9e0a74b 100644 --- a/background.js +++ b/background.js @@ -3,6 +3,11 @@ const reData = new RegExp('^data:(.*?);base64,(.*)$'); async function handleClick(tab, e) { + if (e.modifiers.includes('Shift')) { + await sendPaste(); + return; + } + const imgURL = await browser.tabs.captureTab(tab.id); const selecteds = await browser.tabs.executeScript( @@ -75,6 +80,17 @@ async function handleChangeInt(e) { await browser.storage.local.remove([key]); } +async function sendPaste() { + const clip = await navigator.clipboard.readText(); + + const store = {}; + store[`create_${crypto.randomUUID()}`] = { + name: 'Paste', + html_notes: `${escapeHTML(clip)}`, + }; + await browser.storage.local.set(store); +} + async function create(cfg, task) { const req = { data: { diff --git a/manifest.json b/manifest.json index 660c081..1d619f2 100644 --- a/manifest.json +++ b/manifest.json @@ -7,6 +7,7 @@ }, "permissions": [ + "clipboardRead", "storage", "unlimitedStorage", ""