@@ -84,33 +84,28 @@ function getConversationId(): string | null {
8484 return match ?. [ 2 ] ?? null ;
8585}
8686
87- function attachViaFileInput ( text : string ) : boolean {
88- const fileInput = document . querySelector < HTMLInputElement > ( "input[type='file']" ) ;
89- if ( ! fileInput ) return false ;
87+ function injectIntoTextarea ( text : string ) {
88+ const textarea =
89+ document . querySelector < HTMLElement > ( "div[aria-label='Enter a prompt for Gemini']" ) ||
90+ document . querySelector < HTMLElement > ( ".ql-editor, [contenteditable='true']" ) ;
91+ if ( ! textarea ) return ;
9092
9193 const file = new File ( [ text ] , "AI_Chat_Backup_Context_Seed.txt" , {
9294 type : "text/plain" ,
9395 lastModified : Date . now ( ) ,
9496 } ) ;
9597
96- const dt = new DataTransfer ( ) ;
97- dt . items . add ( file ) ;
98- fileInput . files = dt . files ;
99- fileInput . dispatchEvent ( new Event ( "change" , { bubbles : true } ) ) ;
100- return true ;
101- }
98+ const dataTransfer = new DataTransfer ( ) ;
99+ dataTransfer . items . add ( file ) ;
102100
103- function injectIntoTextarea ( text : string ) {
104- if ( attachViaFileInput ( text ) ) return ;
105-
106- // File input not yet in DOM – retry for up to 5 s
107- let attempts = 0 ;
108- const interval = setInterval ( ( ) => {
109- attempts ++ ;
110- if ( attachViaFileInput ( text ) || attempts > 20 ) {
111- clearInterval ( interval ) ;
112- }
113- } , 250 ) ;
101+ const pasteEvent = new ClipboardEvent ( "paste" , {
102+ bubbles : true ,
103+ cancelable : true ,
104+ clipboardData : dataTransfer ,
105+ } ) ;
106+
107+ textarea . focus ( ) ;
108+ textarea . dispatchEvent ( pasteEvent ) ;
114109}
115110
116111mountWidget (
0 commit comments