File tree Expand file tree Collapse file tree
rustedwarfareapicode/.vitepress/theme Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ async function init() {
1818
1919 for ( let i = 0 ; i < copyBtnList . length ; i ++ ) {
2020 const btn = copyBtnList [ i ] ;
21- btn . addEventListener ( "touchend" , ( ) => {
21+ btn . addEventListener ( "touchend" , async ( ) => {
2222 alert ( "touchend" ) ;
2323 const parentDiv = btn . parentNode ;
2424 const codeElem = parentDiv . querySelector ( "code" ) ;
@@ -27,20 +27,18 @@ async function init() {
2727 ...new Set ( spans . map ( ( span ) => span . textContent ) ) ,
2828 ] . join ( "" ) ;
2929
30- if ( navigator . clipboard ) {
31- navigator . clipboard . writeText ( textToCopy ) . then ( ( ) => {
32- console . log ( "Text copied to clipboard" ) ;
33- } ) ;
34- } else {
30+ try {
31+ await navigator . clipboard . writeText ( textToCopy ) ;
32+ console . log ( "Text copied to clipboard" ) ;
33+ } catch ( error ) {
3534 const textarea = document . createElement ( "textarea" ) ;
3635 textarea . value = textToCopy ;
3736 document . body . appendChild ( textarea ) ;
3837 textarea . select ( ) ;
3938 document . execCommand ( "copy" ) ;
4039 document . body . removeChild ( textarea ) ;
40+ console . log ( "Text copied to clipboard" ) ;
4141 }
42-
43- console . log ( textToCopy ) ;
4442 } ) ;
4543 }
4644 } catch ( error ) {
You can’t perform that action at this time.
0 commit comments