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 @@ -6,6 +6,14 @@ function wait(timeout) {
66 return new Promise ( ( resolve ) => setTimeout ( resolve , timeout ) ) ;
77}
88
9+ async function requestClipboardPermission ( ) {
10+ try {
11+ await navigator . permissions . query ( { name : "clipboard-write" } ) ;
12+ } catch ( error ) {
13+ console . error ( error ) ;
14+ }
15+ }
16+
917async function init ( ) {
1018 try {
1119 await wait ( 1000 ) ;
@@ -19,13 +27,17 @@ async function init() {
1927 for ( let i = 0 ; i < copyBtnList . length ; i ++ ) {
2028 const btn = copyBtnList [ i ] ;
2129 btn . addEventListener ( "touchend" , async ( ) => {
30+ // 请求剪贴板权限
31+ await requestClipboardPermission ( ) ;
32+
2233 alert ( "touchend" ) ;
2334 const parentDiv = btn . parentNode ;
2435 const codeElem = parentDiv . querySelector ( "code" ) ;
2536 const spans = [ ...codeElem . querySelectorAll ( "span" ) ] ;
2637 const textToCopy = [
2738 ...new Set ( spans . map ( ( span ) => span . textContent ) ) ,
2839 ] . join ( "" ) ;
40+ console . log ( textToCopy ) ;
2941
3042 try {
3143 await navigator . clipboard . writeText ( textToCopy ) ;
You can’t perform that action at this time.
0 commit comments