From 1f433048c71ca01dd46c05f3ea44e6eda8510139 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sat, 25 Mar 2023 21:02:14 +0800 Subject: [PATCH] feat: better prompt for searching and some fix --- src/content-script/index.jsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/content-script/index.jsx b/src/content-script/index.jsx index 6161654..96054de 100644 --- a/src/content-script/index.jsx +++ b/src/content-script/index.jsx @@ -73,15 +73,21 @@ async function mountComponent(siteConfig, userConfig) { * @returns {Promise} */ async function getInput(inputQuery) { + let input if (typeof inputQuery === 'function') { - const input = await inputQuery() + input = await inputQuery() if (input) return `Reply in ${await getPreferredLanguage()}.\n` + input return input } const searchInput = getPossibleElementByQuerySelector(inputQuery) if (searchInput) { - if (searchInput.value) return searchInput.value - else if (searchInput.textContent) return searchInput.textContent + if (searchInput.value) input = searchInput.value + else if (searchInput.textContent) input = searchInput.textContent + if (input) + return ( + `Reply in ${await getPreferredLanguage()}.\nThe following is a search input in a search engine, giving useful content or solutions related to it:\n` + + input + ) } } @@ -215,13 +221,12 @@ async function prepareForRightClickMenu() { if (message.type === 'CREATE_MENU') { const data = message.data let prompt = '' - if (data.itemId in toolsConfig) + if (data.itemId in toolsConfig) { prompt = await toolsConfig[data.itemId].genPrompt(data.selectionText) - else if (data.itemId in menuConfig) - prompt = cropText( - `Reply in ${await getPreferredLanguage()}.\n` + - (await menuConfig[data.itemId].genPrompt()), - ) + } else if (data.itemId in menuConfig) { + prompt = await menuConfig[data.itemId].genPrompt() + if (prompt) prompt = cropText(`Reply in ${await getPreferredLanguage()}.\n` + prompt) + } const position = { x: menuX, y: menuY } const container = createElementAtPosition(position.x, position.y)