Skip to content

Commit fc75302

Browse files
committed
feat: better prompt for searching and some fix
1 parent 27d87d6 commit fc75302

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/content-script/index.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,21 @@ async function mountComponent(siteConfig, userConfig) {
7373
* @returns {Promise<string>}
7474
*/
7575
async function getInput(inputQuery) {
76+
let input
7677
if (typeof inputQuery === 'function') {
77-
const input = await inputQuery()
78+
input = await inputQuery()
7879
if (input) return `Reply in ${await getPreferredLanguage()}.\n` + input
7980
return input
8081
}
8182
const searchInput = getPossibleElementByQuerySelector(inputQuery)
8283
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+
)
8591
}
8692
}
8793

@@ -215,13 +221,12 @@ async function prepareForRightClickMenu() {
215221
if (message.type === 'CREATE_MENU') {
216222
const data = message.data
217223
let prompt = ''
218-
if (data.itemId in toolsConfig)
224+
if (data.itemId in toolsConfig) {
219225
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+
}
225230

226231
const position = { x: menuX, y: menuY }
227232
const container = createElementAtPosition(position.x, position.y)

0 commit comments

Comments
 (0)