From ac789e578690b5a984b2effb2967b5ec4e41d5f2 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Thu, 27 Jul 2023 22:46:49 -0400 Subject: [PATCH] Highlighted text saved to notes on creation (#20) --- manifests/manifest.COMMON.json | 4 +++- src/background.js | 10 ++++++---- src/form.svelte | 10 +++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/manifests/manifest.COMMON.json b/manifests/manifest.COMMON.json index e92c226..9331e82 100644 --- a/manifests/manifest.COMMON.json +++ b/manifests/manifest.COMMON.json @@ -37,6 +37,8 @@ "tabs", "storage", "contextMenus", - "notifications" + "notifications", + "scripting", + "activeTab" ] } diff --git a/src/background.js b/src/background.js index ed0d3c3..bba12bc 100644 --- a/src/background.js +++ b/src/background.js @@ -144,10 +144,12 @@ async function saveToLinkding(info, tab) { } } -chrome.contextMenus.create({ - id: "save-to-linkding", - title: "Save bookmark", - contexts: ["link"], +chrome.contextMenus.removeAll(() => { + chrome.contextMenus.create({ + id: "save-to-linkding", + title: "Save bookmark", + contexts: ["link"], + }); }); chrome.contextMenus.onClicked.addListener(saveToLinkding); diff --git a/src/form.svelte b/src/form.svelte index 108bbe8..8f70d74 100644 --- a/src/form.svelte +++ b/src/form.svelte @@ -35,6 +35,14 @@ const tabInfo = await getCurrentTabInfo(); url = tabInfo.url; + const highlightedText = await chrome.scripting.executeScript({ + target: { tabId : tabInfo.id }, + func: () => window.getSelection().toString(), + }); + if (highlightedText?.[0]?.result) { + notes = highlightedText[0].result; + } + tags = configuration.default_tags; const availableTags = await api.getTags().catch(() => []); availableTagNames = availableTags.map((tag) => tag.name); @@ -310,7 +318,7 @@ } .delete-button { - color: #ff0000; + color: #e05a5b; cursor: pointer; }