@@ -73,15 +73,21 @@ async function mountComponent(siteConfig, userConfig) {
73
73
* @returns {Promise<string> }
74
74
*/
75
75
async function getInput ( inputQuery ) {
76
+ let input
76
77
if ( typeof inputQuery === 'function' ) {
77
- const input = await inputQuery ( )
78
+ input = await inputQuery ( )
78
79
if ( input ) return `Reply in ${ await getPreferredLanguage ( ) } .\n` + input
79
80
return input
80
81
}
81
82
const searchInput = getPossibleElementByQuerySelector ( inputQuery )
82
83
if ( searchInput ) {
83
- if ( searchInput . value ) return searchInput . value
84
- else if ( searchInput . textContent ) return searchInput . textContent
84
+ if ( searchInput . value ) input = searchInput . value
85
+ else if ( searchInput . textContent ) input = searchInput . textContent
86
+ if ( input )
87
+ return (
88
+ `Reply in ${ await getPreferredLanguage ( ) } .\nThe following is a search input in a search engine, giving useful content or solutions related to it:\n` +
89
+ input
90
+ )
85
91
}
86
92
}
87
93
@@ -215,13 +221,12 @@ async function prepareForRightClickMenu() {
215
221
if ( message . type === 'CREATE_MENU' ) {
216
222
const data = message . data
217
223
let prompt = ''
218
- if ( data . itemId in toolsConfig )
224
+ if ( data . itemId in toolsConfig ) {
219
225
prompt = await toolsConfig [ data . itemId ] . genPrompt ( data . selectionText )
220
- else if ( data . itemId in menuConfig )
221
- prompt = cropText (
222
- `Reply in ${ await getPreferredLanguage ( ) } .\n` +
223
- ( await menuConfig [ data . itemId ] . genPrompt ( ) ) ,
224
- )
226
+ } else if ( data . itemId in menuConfig ) {
227
+ prompt = await menuConfig [ data . itemId ] . genPrompt ( )
228
+ if ( prompt ) prompt = cropText ( `Reply in ${ await getPreferredLanguage ( ) } .\n` + prompt )
229
+ }
225
230
226
231
const position = { x : menuX , y : menuY }
227
232
const container = createElementAtPosition ( position . x , position . y )
0 commit comments