(inputQuery)
| 175 | } |
| 176 | |
| 177 | async function getInput(inputQuery) { |
| 178 | console.debug('[content] getInput called with query:', inputQuery) |
| 179 | try { |
| 180 | let input |
| 181 | if (typeof inputQuery === 'function') { |
| 182 | console.debug('[content] Input query is a function.') |
| 183 | input = await inputQuery() |
| 184 | if (input) { |
| 185 | const preferredLanguage = await getPreferredLanguage() |
| 186 | const replyPromptBelow = `Reply in ${preferredLanguage}. Regardless of the language of content I provide below. !!This is very important!!` |
| 187 | const replyPromptAbove = `Reply in ${preferredLanguage}. Regardless of the language of content I provide above. !!This is very important!!` |
| 188 | const result = `${replyPromptBelow}\n\n${input}\n\n${replyPromptAbove}` |
| 189 | console.debug('[content] getInput from function generated prompt.', { |
| 190 | inputLength: input.length, |
| 191 | promptLength: result.length, |
| 192 | }) |
| 193 | return result |
| 194 | } |
| 195 | console.debug('[content] getInput from function returned no input.') |
| 196 | return input |
| 197 | } |
| 198 | console.debug('[content] Input query is a selector.') |
| 199 | const searchInput = getPossibleElementByQuerySelector(inputQuery) |
| 200 | if (searchInput) { |
| 201 | console.debug('[content] Found search input element:', searchInput) |
| 202 | if (searchInput.value) input = searchInput.value |
| 203 | else if (searchInput.textContent) input = searchInput.textContent |
| 204 | if (input) { |
| 205 | const preferredLanguage = await getPreferredLanguage() |
| 206 | const result = |
| 207 | `Reply in ${preferredLanguage}.\nThe following is a search input in a search engine, ` + |
| 208 | `giving useful content or solutions and as much information as you can related to it, ` + |
| 209 | `use markdown syntax to make your answer more readable, such as code blocks, bold, list:\n` + |
| 210 | input |
| 211 | console.debug('[content] getInput from selector generated prompt.', { |
| 212 | inputLength: input.length, |
| 213 | promptLength: result.length, |
| 214 | }) |
| 215 | return result |
| 216 | } |
| 217 | } |
| 218 | console.debug('[content] No input found from selector or element empty.') |
| 219 | return undefined |
| 220 | } catch (error) { |
| 221 | console.error('[content] Error in getInput:', error) |
| 222 | return undefined |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | let toolbarContainer |
| 227 | const deleteToolbar = () => { |
no test coverage detected