File tree Expand file tree Collapse file tree
CodeTrans/ui/svelte/src/routes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 8383 let deleteFlag: boolean = false ;
8484 let inputClick: boolean = true ;
8585
86- function handelCopy() {
87- navigator .clipboard .writeText (output );
88- copyText = " copied!" ;
86+ async function handelCopy() {
87+ try {
88+ if (navigator .clipboard && navigator .clipboard .writeText ) {
89+ await navigator .clipboard .writeText (output );
90+ copyText = " copied!" ;
91+ } else {
92+ const textArea = document .createElement (' textarea' );
93+ textArea .value = output ;
94+ textArea .style .position = ' fixed' ;
95+ textArea .style .left = ' -999999px' ;
96+ textArea .style .top = ' -999999px' ;
97+ document .body .appendChild (textArea );
98+ textArea .focus ();
99+ textArea .select ();
100+
101+ if (document .execCommand (' copy' )) {
102+ copyText = " copied!" ;
103+ } else {
104+ copyText = " copy failed" ;
105+ }
106+
107+ document .body .removeChild (textArea );
108+ }
109+ } catch (err ) {
110+ console .error (' Copy failed:' , err );
111+ copyText = " copy failed" ;
112+ }
113+
89114 setTimeout (() => {
90115 copyText = " copy" ;
91- }, 1000 );
116+ }, 2000 );
92117 }
93118
94119 function handelInputClick() {
You can’t perform that action at this time.
0 commit comments