From bb3023cd5cb5857cdc20febd18e0ff0b5338c561 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 18 Oct 2022 23:29:16 -0700 Subject: [PATCH] Add selected text to notes --- background.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index 3343b60..0eb248e 100644 --- a/background.js +++ b/background.js @@ -5,10 +5,29 @@ const reData = new RegExp('^data:(.*?);base64,(.*)$'); async function handleClick(tab, e) { const imgURL = await browser.tabs.captureTab(tab.id); + const selecteds = await browser.tabs.executeScript( + tab.id, + { + code: 'getSelection().toString()', + }, + ); + const selected = selecteds.filter(x => x).join('\n'); + + let noteParts = [ + ``, + `${escapeHTML(tab.url)}`, + ]; + + if (selected) { + noteParts.push(`\n\n${escapeHTML(selected)}`); + } + + noteParts.push(''); + const store = {}; store[`create_${crypto.randomUUID()}`] = { name: tab.title, - html_notes: `${escapeHTML(tab.url)}`, + html_notes: noteParts.join(''), attach: imgURL, filename: 'screenshot.png', };