@@ -68,9 +68,11 @@ module.exports.contextMenuCopyAddressAtPublicGw = contextMenuCopyAddressAtPublic
68
68
module . exports . contextMenuViewOnGateway = contextMenuViewOnGateway
69
69
module . exports . contextMenuCopyPermalink = contextMenuCopyPermalink
70
70
71
- // menu items that are enabled only when API is online
71
+ // menu item ids for things that are enabled only when API is online (static)
72
+ const apiMenuItemIds = new Set ( [ contextMenuCopyRawCid , contextMenuCopyCanonicalAddress , contextMenuImportToIpfs ] )
73
+ // menu items that are enabled only when API is online (dynamic)
72
74
const apiMenuItems = new Set ( )
73
- // menu items enabled only in IPFS context
75
+ // menu items enabled only in IPFS context (dynamic)
74
76
const ipfsContextItems = new Set ( )
75
77
76
78
function createContextMenus ( getState , runtime , ipfsPathValidator , { onAddFromContext, onCopyCanonicalAddress, onCopyRawCid, onCopyAddressAtPublicGw } ) {
@@ -104,15 +106,19 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
104
106
const itemId = `${ parentId } _${ id } `
105
107
ipfsContextItems . add ( itemId )
106
108
// some items also require API access
107
- if ( id === contextMenuCopyRawCid ) {
109
+ if ( apiMenuItemIds . has ( id ) ) {
108
110
apiMenuItems . add ( itemId )
109
111
}
110
112
return browser . contextMenus . create ( {
111
113
id : itemId ,
112
114
parentId,
113
115
title : browser . i18n . getMessage ( id ) ,
114
116
contexts : [ contextType ] ,
115
- documentUrlPatterns : [ '*://*/ipfs/*' , '*://*/ipns/*' ] ,
117
+ documentUrlPatterns : [
118
+ '*://*/ipfs/*' , '*://*/ipns/*' ,
119
+ '*://*.ipfs.dweb.link/*' , '*://*.ipns.dweb.link/*' , // TODO: add any custom public gateway from Preferences
120
+ '*://*.ipfs.localhost/*' , '*://*.ipns.localhost/*'
121
+ ] ,
116
122
/* no support for 'icons' in Chrome
117
123
icons: {
118
124
'48': '/ui-kit/icons/stroke_copy.svg'
@@ -124,7 +130,8 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
124
130
createSubmenu ( parentId , contextType )
125
131
createImportToIpfsMenuItem ( parentId , contextMenuImportToIpfs , contextType , { wrapWithDirectory : true , pin : false } )
126
132
createCopierMenuItem ( parentId , contextMenuCopyAddressAtPublicGw , contextType , onCopyAddressAtPublicGw )
127
- createCopierMenuItem ( parentId , contextMenuCopyCanonicalAddress , contextType , onCopyCanonicalAddress )
133
+ // TODO: below needs refactor to support for both IPFS and IPNS, like one added to browser action in https://github.com/ipfs-shipyard/ipfs-companion/pull/937
134
+ // createCopierMenuItem(parentId, contextMenuCopyCanonicalAddress, contextType, onCopyCanonicalAddress)
128
135
createCopierMenuItem ( parentId , contextMenuCopyRawCid , contextType , onCopyRawCid )
129
136
}
130
137
0 commit comments