205205 .image-modal .close : hover {
206206 color : # bbb ;
207207 }
208+
209+ /* Copy button styling */
210+ .copy-button {
211+ position : absolute;
212+ top : 8px ;
213+ right : 8px ;
214+ background : rgba (99 , 102 , 241 , 0.8 );
215+ color : white;
216+ border : none;
217+ border-radius : 4px ;
218+ padding : 4px 8px ;
219+ font-size : 12px ;
220+ cursor : pointer;
221+ opacity : 0 ;
222+ transition : opacity 0.2s ;
223+ }
224+ .copy-button : hover {
225+ background : rgba (99 , 102 , 241 , 1 );
226+ }
227+ .message-bubble-ai : hover .copy-button ,
228+ .message-bubble-user : hover .copy-button {
229+ opacity : 1 ;
230+ }
231+ .message-bubble-ai ,
232+ .message-bubble-user {
233+ position : relative;
234+ }
208235 </ style >
209236</ head >
210237< body class ="bg-light-bg dark:bg-dev-darker min-h-screen text-light-text dark:text-dev-text transition-colors duration-300 ">
@@ -314,6 +341,7 @@ <h1 class="text-3xl font-bold text-dev-accent">🤖 AI Agent</h1>
314341 messageDiv . innerHTML = `
315342 <div class="ml-auto flex">
316343 <div class="message-bubble-user rounded-lg p-3 max-w-3xl">
344+ <button class="copy-button" data-copy-text="File attached: ${ file . name } ">📋</button>
317345 <p class="text-light-text dark:text-dev-text mb-2">📎 File attached: ${ file . name } </p>
318346 <img src="${ imageUrl } " alt="${ file . name } " class="max-w-full max-h-64 rounded border border-light-border dark:border-dev-border cursor-pointer hover:opacity-80 transition" onclick="openImageModal('${ imageUrl } ')" />
319347 </div>
@@ -326,6 +354,23 @@ <h1 class="text-3xl font-bold text-dev-accent">🤖 AI Agent</h1>
326354 messageContainer . scrollTop = messageContainer . scrollHeight ;
327355 }
328356
357+ // Copy to clipboard function
358+ function copyToClipboard ( text ) {
359+ navigator . clipboard . writeText ( text ) . then ( function ( ) {
360+ console . log ( 'Text copied to clipboard' ) ;
361+ } ) . catch ( function ( err ) {
362+ console . error ( 'Failed to copy text: ' , err ) ;
363+ } ) ;
364+ }
365+
366+ // Event delegation for copy buttons
367+ messageContainer . addEventListener ( 'click' , function ( e ) {
368+ if ( e . target . classList . contains ( 'copy-button' ) ) {
369+ const textToCopy = e . target . getAttribute ( 'data-copy-text' ) ;
370+ copyToClipboard ( textToCopy ) ;
371+ }
372+ } ) ;
373+
329374 // Function to send document analysis with empty prompt and clear file after
330375 async function sendDocumentAnalysis ( ) {
331376 try {
@@ -427,6 +472,7 @@ <h1 class="text-3xl font-bold text-dev-accent">🤖 AI Agent</h1>
427472 messageDiv . innerHTML = `
428473 <div class="ml-auto flex">
429474 <div class="message-bubble-user rounded-lg p-3 max-w-3xl">
475+ <button class="copy-button" data-copy-text="${ escapeHtml ( content ) } ">📋</button>
430476 <p class="text-light-text dark:text-dev-text">${ escapeHtml ( content ) } </p>
431477 </div>
432478 <div class="w-10 h-10 rounded-full bg-dev-secondary bg-opacity-20 flex items-center justify-center ml-3">
@@ -445,6 +491,7 @@ <h1 class="text-3xl font-bold text-dev-accent">🤖 AI Agent</h1>
445491 <span class="text-lg">🤖</span>
446492 </div>
447493 <div class="message-bubble-ai rounded-lg p-3 max-w-4xl ai-response">
494+ <button class="copy-button" data-copy-text="${ escapeHtml ( content ) } ">📋</button>
448495 ${ renderedContent }
449496 </div>
450497 ` ;
0 commit comments