Skip to content

Commit

Permalink
Highlighted text saved to notes on creation (sissbruecker#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Georges-Antoine Assi committed Jul 28, 2023
1 parent 874b74a commit ac789e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion manifests/manifest.COMMON.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"tabs",
"storage",
"contextMenus",
"notifications"
"notifications",
"scripting",
"activeTab"
]
}
10 changes: 6 additions & 4 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion src/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -310,7 +318,7 @@
}
.delete-button {
color: #ff0000;
color: #e05a5b;
cursor: pointer;
}
Expand Down

0 comments on commit ac789e5

Please sign in to comment.