@@ -6,18 +6,22 @@ chrome.omnibox.onInputEntered.addListener((input) => {
6
6
const detaInstance = items . detaInstance
7
7
8
8
if ( ! detaInstance ) {
9
- return
9
+ return chrome . runtime . openOptionsPage ( )
10
10
}
11
11
12
12
const newURL = encodeURIComponent ( input )
13
13
chrome . tabs . update ( undefined , { url : `${ detaInstance } ?addUrl=${ newURL } ` , highlighted : false } )
14
14
} )
15
15
} )
16
16
17
- chrome . contextMenus . onClicked . addListener ( ( { menuItemId } ) => {
17
+ chrome . contextMenus . onClicked . addListener ( ( { menuItemId, linkUrl } ) => {
18
18
chrome . storage . local . get ( ( items ) => {
19
19
const detaInstance = items . detaInstance
20
20
21
+ if ( ! detaInstance ) {
22
+ return chrome . runtime . openOptionsPage ( )
23
+ }
24
+
21
25
if ( menuItemId === 'view-links' ) {
22
26
chrome . tabs . create ( {
23
27
url : detaInstance
@@ -30,6 +34,10 @@ chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
30
34
chrome . tabs . create ( {
31
35
url : 'https://webcrate.app/docs'
32
36
} )
37
+ } else if ( menuItemId === 'save-link' ) {
38
+ chrome . tabs . create ( {
39
+ url : `${ detaInstance } ?addUrl=${ linkUrl } `
40
+ } )
33
41
} else if ( menuItemId === 'open-settings' ) {
34
42
chrome . runtime . openOptionsPage ( )
35
43
}
@@ -62,6 +70,12 @@ chrome.contextMenus.create({
62
70
contexts : [ 'browser_action' ]
63
71
} )
64
72
73
+ chrome . contextMenus . create ( {
74
+ title : 'Save link to WebCrate' ,
75
+ id : 'save-link' ,
76
+ contexts : [ 'link' ]
77
+ } )
78
+
65
79
// Show settings page after install
66
80
chrome . runtime . onInstalled . addListener ( ( details ) => {
67
81
if ( details . reason === 'install' ) {
0 commit comments