File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed
examples/bedtime-story-teller/assets Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -444,19 +444,26 @@ document.addEventListener('DOMContentLoaded', () => {
444444 } ) ;
445445
446446 document . getElementById ( 'copy-story-button' ) . addEventListener ( 'click' , ( ) => {
447- const storyText = document . getElementById ( 'story-response' ) . textContent ;
448- navigator . clipboard . writeText ( storyText ) . then ( ( ) => {
449- const copyButton = document . getElementById ( 'copy-story-button' ) ;
450- const originalHTML = copyButton . innerHTML ;
447+ const storyText = document . getElementById ( 'story-response' ) . innerText ;
448+ const copyButton = document . getElementById ( 'copy-story-button' ) ;
449+ const originalHTML = copyButton . innerHTML ;
450+ const textarea = document . createElement ( 'textarea' ) ;
451+ textarea . value = storyText ;
452+ document . body . appendChild ( textarea ) ;
453+ textarea . select ( ) ;
454+ try {
455+ document . execCommand ( 'copy' ) ;
451456 copyButton . textContent = 'Copied!' ;
452457 copyButton . disabled = true ;
453- setTimeout ( ( ) => {
454- copyButton . innerHTML = originalHTML ;
455- copyButton . disabled = false ;
456- } , 2000 ) ;
457- } , ( err ) => {
458+ } catch ( err ) {
458459 console . error ( 'Could not copy text: ' , err ) ;
459- } ) ;
460+ }
461+ document . body . removeChild ( textarea ) ;
462+
463+ setTimeout ( ( ) => {
464+ copyButton . innerHTML = originalHTML ;
465+ copyButton . disabled = false ;
466+ } , 2000 ) ;
460467 } ) ;
461468
462469 document . getElementById ( 'generate-randomly-button' ) . addEventListener ( 'click' , ( ) => {
Original file line number Diff line number Diff line change @@ -639,6 +639,7 @@ body {
639639 line-height : 1.6 ;
640640 white-space : pre-wrap;
641641 overflow-y : auto;
642+ max-height : 60vh ; /* Added for fixed height and scrollbar */
642643}
643644
644645# prompt-display strong {
You can’t perform that action at this time.
0 commit comments