page.js 843 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Initialize prettify for syntax highlighting
  2. if ( typeof prettyPrint === 'function' ) {
  3. prettyPrint();
  4. }
  5. // Add code copy buttons
  6. ( function addCopyButtons() {
  7. const elements = document.getElementsByTagName( 'pre' );
  8. for ( let i = 0; i < elements.length; i ++ ) {
  9. const element = elements[ i ];
  10. if ( element.classList.contains( 'linenums' ) === false ) {
  11. const copyButton = document.createElement( 'button' );
  12. copyButton.className = 'copy-btn';
  13. element.appendChild( copyButton );
  14. copyButton.addEventListener( 'click', function () {
  15. const codeContent = element.textContent;
  16. navigator.clipboard.writeText( codeContent ).then( () => {
  17. copyButton.classList.add( 'copied' );
  18. setTimeout( () => {
  19. copyButton.classList.remove( 'copied' );
  20. }, 1000 );
  21. } );
  22. } );
  23. }
  24. }
  25. } )();
粤ICP备19079148号