@@ -152,18 +152,26 @@ Browser.runtime.onMessage.addListener(async (message) => {
152
152
} )
153
153
154
154
Browser . commands . onCommand . addListener ( async ( command ) => {
155
- const currentTab = ( await Browser . tabs . query ( { active : true , currentWindow : true } ) ) [ 0 ]
156
155
const message = {
157
156
itemId : command ,
158
157
selectionText : '' ,
159
158
useMenuPosition : false ,
160
159
}
161
160
console . debug ( 'command triggered' , message )
162
- if ( command in menuConfig && menuConfig [ command ] . action ) menuConfig [ command ] . action ( )
163
- Browser . tabs . sendMessage ( currentTab . id , {
164
- type : 'CREATE_CHAT' ,
165
- data : message ,
166
- } )
161
+
162
+ if ( command in menuConfig ) {
163
+ if ( menuConfig [ command ] . action ) {
164
+ menuConfig [ command ] . action ( )
165
+ }
166
+
167
+ if ( menuConfig [ command ] . genPrompt ) {
168
+ const currentTab = ( await Browser . tabs . query ( { active : true , currentWindow : true } ) ) [ 0 ]
169
+ Browser . tabs . sendMessage ( currentTab . id , {
170
+ type : 'CREATE_CHAT' ,
171
+ data : message ,
172
+ } )
173
+ }
174
+ }
167
175
} )
168
176
169
177
function refreshMenu ( ) {
@@ -212,12 +220,24 @@ function refreshMenu() {
212
220
useMenuPosition : tab . id === currentTab . id ,
213
221
}
214
222
console . debug ( 'menu clicked' , message )
215
- if ( message . itemId in menuConfig && menuConfig [ message . itemId ] . action )
216
- menuConfig [ message . itemId ] . action ( )
217
- Browser . tabs . sendMessage ( currentTab . id , {
218
- type : 'CREATE_CHAT' ,
219
- data : message ,
220
- } )
223
+
224
+ if ( defaultConfig . selectionTools . includes ( message . itemId ) ) {
225
+ Browser . tabs . sendMessage ( currentTab . id , {
226
+ type : 'CREATE_CHAT' ,
227
+ data : message ,
228
+ } )
229
+ } else if ( message . itemId in menuConfig ) {
230
+ if ( menuConfig [ message . itemId ] . action ) {
231
+ menuConfig [ message . itemId ] . action ( )
232
+ }
233
+
234
+ if ( menuConfig [ message . itemId ] . genPrompt ) {
235
+ Browser . tabs . sendMessage ( currentTab . id , {
236
+ type : 'CREATE_CHAT' ,
237
+ data : message ,
238
+ } )
239
+ }
240
+ }
221
241
} )
222
242
} )
223
243
} )
0 commit comments