File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1919 gtag ( 'js' , new Date ( ) ) ;
2020
2121 gtag ( 'config' , 'UA-102564547-3' ) ;
22+
23+ window . onload = function ( ) {
24+ function copyToClipboard ( ) {
25+ const textId = this . id . replace ( 'btn' , 'code' )
26+ const copyText = document . getElementById ( textId ) ;
27+ const text = copyText . textContent || copyText . innerText ;
28+
29+ const input = document . createElement ( 'textarea' ) ;
30+ input . innerHTML = text ;
31+ document . body . appendChild ( input ) ;
32+ input . select ( ) ;
33+ input . setSelectionRange ( 0 , 99999 ) ;
34+ document . execCommand ( 'copy' ) ;
35+ document . body . removeChild ( input ) ;
36+
37+ this . innerHTML = '✔️' ;
38+ setTimeout ( ( ) => {
39+ this . innerHTML = '📋' ;
40+ } , 2000 )
41+ }
42+ let codes = document . querySelectorAll ( '.highlight > pre > code' ) ;
43+ let count = 0 ;
44+ codes . forEach ( ( code ) => {
45+ code . setAttribute ( "id" , `code-${ count } ` ) ;
46+ const btn = document . createElement ( 'button' ) ;
47+ btn . innerHTML = "📋" ;
48+ btn . className = "btn-copy" ;
49+ btn . setAttribute ( "id" , `btn-${ count } ` ) ;
50+ btn . addEventListener ( "click" , copyToClipboard ) ;
51+ code . before ( btn ) ;
52+ count ++ ;
53+ } ) ;
54+ }
2255 </ script >
2356</ html >
Original file line number Diff line number Diff line change 152152 }
153153 }
154154
155+ .highlight {
156+ position : relative ;
157+ }
158+ .btn-copy {
159+ position : absolute ;
160+ right : 10px ;
161+ background : none ;
162+ border : none ;
163+ }
164+
155165 .toggles {
156166 text-align : right ;
157167 padding-top : 15px ;
You can’t perform that action at this time.
0 commit comments