@@ -356,6 +356,54 @@ class PaginationNavigator {
356356 }
357357}
358358
359+ // Copy to Clipboard (using `navigator.clipboard`)
360+
361+ function enableCopyToClipboard ( selector ) {
362+ const elements = document . querySelectorAll ( selector ) ;
363+
364+ elements . forEach ( element => {
365+ element . addEventListener ( "click" , async ( ) => {
366+ let textToCopy = "" ;
367+
368+ // Determine the text to copy
369+ if ( element . hasAttribute ( "data-copy" ) ) {
370+ textToCopy = element . getAttribute ( "data-copy" ) ; // From a custom attribute
371+ } else if ( element . value ) {
372+ textToCopy = element . value ; // From an input field
373+ } else {
374+ textToCopy = element . innerText . trim ( ) ; // From the element's text
375+ }
376+
377+ // Default tooltip text or custom text from data-copy-feedback attribute
378+ const tooltipText = element . getAttribute ( 'data-copy-feedback' ) || 'Copied!' ;
379+
380+ if ( textToCopy ) {
381+ try {
382+ await navigator . clipboard . writeText ( textToCopy ) . then ( ( ) => {
383+ // Create a tooltip
384+ const tooltip = document . createElement ( 'span' ) ;
385+ tooltip . classList . add ( 'copy-tooltip' ) ;
386+ tooltip . textContent = tooltipText ;
387+ element . appendChild ( tooltip ) ;
388+
389+ // Show the tooltip
390+ setTimeout ( ( ) => {
391+ tooltip . classList . add ( 'visible' ) ;
392+ } , 0 ) ; // Add class immediately to trigger CSS transition
393+
394+ // Remove the tooltip after 1.5 seconds
395+ setTimeout ( ( ) => {
396+ element . removeChild ( tooltip ) ;
397+ } , 1500 ) ;
398+ } ) ;
399+ } catch ( err ) {
400+ console . error ( "Clipboard copy failed:" , err ) ;
401+ }
402+ }
403+ } ) ;
404+ } ) ;
405+ }
406+
359407document . addEventListener ( 'DOMContentLoaded' , function ( ) {
360408
361409 setupOpenModalButtons ( ) ;
@@ -365,6 +413,7 @@ document.addEventListener('DOMContentLoaded', function () {
365413 setupTextarea ( ) ;
366414 setupHighlightControls ( ) ;
367415 setupSelectCheckbox ( ) ;
416+ enableCopyToClipboard ( ".copy-to-clipboard" ) ;
368417
369418 const paginationContainer = document . querySelector ( "#pagination-header" ) ;
370419 if ( paginationContainer ) {
0 commit comments