@@ -137,40 +137,6 @@ if (is_ai_studio) {
137137 chatbot = z_ai
138138}
139139
140- export const get_textarea_element = ( ) => {
141- const chatbot_selectors = {
142- [ ai_studio_url ] : 'textarea' ,
143- [ gemini_url ] : 'div[contenteditable="true"]' ,
144- [ openrouter_url ] : 'textarea' ,
145- [ chatgpt_url ] : 'div#prompt-textarea' ,
146- [ copilot_url ] : 'textarea' ,
147- [ grok_url ] : 'div[contenteditable="true"]' ,
148- [ deepseek_url ] : 'textarea' ,
149- [ mistral_url ] : 'div[contenteditable="true"]' ,
150- [ yuanbao_url ] : 'div[contenteditable="true"]' ,
151- [ doubao_url ] : 'textarea' ,
152- [ together_url ] : 'textarea' ,
153- [ z_ai_url ] : 'textarea' ,
154- [ github_copilot_url ] : 'textarea' ,
155- [ hugging_chat_url ] : 'textarea' ,
156- [ lmarena_url ] : 'textarea'
157- } as any
158-
159- // Find the appropriate selector based on the URL without the hash
160- let selector = null
161- for ( const [ url , sel ] of Object . entries ( chatbot_selectors ) ) {
162- if ( current_url . split ( '#' ) [ 0 ] . split ( '?' ) [ 0 ] . startsWith ( url ) ) {
163- selector = sel
164- break
165- }
166- }
167-
168- const active_element = selector
169- ? ( document . querySelector ( selector as string ) as HTMLElement )
170- : ( document . activeElement as HTMLElement )
171- return active_element
172- }
173-
174140const initialize_chat = async ( params : { message : string ; chat : Chat } ) => {
175141 if ( chatbot ?. set_model ) {
176142 await chatbot . set_model ( params . chat )
@@ -199,6 +165,18 @@ const initialize_chat = async (params: { message: string; chat: Chat }) => {
199165 } )
200166 }
201167
168+ window . dispatchEvent ( new CustomEvent ( 'cwc-chat-initialized' ) )
169+ // User may send by pressing enter
170+ await new Promise < void > ( ( resolve ) => {
171+ const handle_key_press = ( e : KeyboardEvent ) => {
172+ if ( e . key == 'Enter' ) {
173+ document . removeEventListener ( 'keydown' , handle_key_press )
174+ resolve ( )
175+ }
176+ }
177+ document . addEventListener ( 'keydown' , handle_key_press )
178+ setTimeout ( resolve , 2000 )
179+ } )
202180 // Process next chat from the queue
203181 browser . runtime . sendMessage < Message > ( {
204182 action : 'chat-initialized'
0 commit comments