Skip to content

Commit 68b3112

Browse files
committed
✨ Add link via right click on URL
1 parent 59af84b commit 68b3112

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/background.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ chrome.omnibox.onInputEntered.addListener((input) => {
66
const detaInstance = items.detaInstance
77

88
if (!detaInstance) {
9-
return
9+
return chrome.runtime.openOptionsPage()
1010
}
1111

1212
const newURL = encodeURIComponent(input)
1313
chrome.tabs.update(undefined, { url: `${ detaInstance }?addUrl=${ newURL }`, highlighted: false })
1414
})
1515
})
1616

17-
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
17+
chrome.contextMenus.onClicked.addListener(({ menuItemId, linkUrl }) => {
1818
chrome.storage.local.get((items) => {
1919
const detaInstance = items.detaInstance
2020

21+
if (!detaInstance) {
22+
return chrome.runtime.openOptionsPage()
23+
}
24+
2125
if (menuItemId === 'view-links') {
2226
chrome.tabs.create({
2327
url: detaInstance
@@ -30,6 +34,10 @@ chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
3034
chrome.tabs.create({
3135
url: 'https://webcrate.app/docs'
3236
})
37+
} else if (menuItemId === 'save-link') {
38+
chrome.tabs.create({
39+
url: `${ detaInstance }?addUrl=${ linkUrl }`
40+
})
3341
} else if (menuItemId === 'open-settings') {
3442
chrome.runtime.openOptionsPage()
3543
}
@@ -62,6 +70,12 @@ chrome.contextMenus.create({
6270
contexts: [ 'browser_action' ]
6371
})
6472

73+
chrome.contextMenus.create({
74+
title: 'Save link to WebCrate',
75+
id: 'save-link',
76+
contexts: [ 'link' ]
77+
})
78+
6579
// Show settings page after install
6680
chrome.runtime.onInstalled.addListener((details) => {
6781
if (details.reason === 'install') {

0 commit comments

Comments
 (0)