Skip to content

Commit

Permalink
✨ Add link via right click on URL
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Aug 27, 2021
1 parent 59af84b commit 68b3112
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ chrome.omnibox.onInputEntered.addListener((input) => {
const detaInstance = items.detaInstance

if (!detaInstance) {
return
return chrome.runtime.openOptionsPage()
}

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

chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
chrome.contextMenus.onClicked.addListener(({ menuItemId, linkUrl }) => {
chrome.storage.local.get((items) => {
const detaInstance = items.detaInstance

if (!detaInstance) {
return chrome.runtime.openOptionsPage()
}

if (menuItemId === 'view-links') {
chrome.tabs.create({
url: detaInstance
Expand All @@ -30,6 +34,10 @@ chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
chrome.tabs.create({
url: 'https://webcrate.app/docs'
})
} else if (menuItemId === 'save-link') {
chrome.tabs.create({
url: `${ detaInstance }?addUrl=${ linkUrl }`
})
} else if (menuItemId === 'open-settings') {
chrome.runtime.openOptionsPage()
}
Expand Down Expand Up @@ -62,6 +70,12 @@ chrome.contextMenus.create({
contexts: [ 'browser_action' ]
})

chrome.contextMenus.create({
title: 'Save link to WebCrate',
id: 'save-link',
contexts: [ 'link' ]
})

// Show settings page after install
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
Expand Down

0 comments on commit 68b3112

Please sign in to comment.