mirror of
				https://github.com/imfing/hextra.git
				synced 2025-10-31 11:54:53 -04:00 
			
		
		
		
	 7a2cca9181
			
		
	
	7a2cca9181
	
	
	
		
			
			fix: navbar icon should use home relative link fix: copy code for raw <code> element fix: missing breadcrumb hover style fix: tabs typo preventing loading the script
		
			
				
	
	
		
			31 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| document.querySelectorAll('.code-copy-btn').forEach(function (button) {
 | |
|   button.addEventListener('click', function (e) {
 | |
|     e.preventDefault();
 | |
|     const targetId = button.getAttribute('data-clipboard-target');
 | |
|     const target = document.querySelector(targetId);
 | |
|     let codeElement;
 | |
|     if (target.tagName === 'CODE') {
 | |
|       codeElement = target;
 | |
|     } else {
 | |
|       // Select the last code element in case line numbers are present
 | |
|       const codeElements = target.querySelectorAll('code');
 | |
|       codeElement = codeElements[codeElements.length - 1];
 | |
|     }
 | |
|     if (codeElement) {
 | |
|       // Replace double newlines with single newlines in the innerText
 | |
|       // as each line inside <span> has trailing newline '\n'
 | |
|       const code = codeElement.innerText.replace(/\n\n/g, '\n');
 | |
|       navigator.clipboard.writeText(code).then(function () {
 | |
|         button.classList.add('copied');
 | |
|         setTimeout(function () {
 | |
|           button.classList.remove('copied');
 | |
|         }, 500);
 | |
|       }).catch(function (err) {
 | |
|         console.error('Failed to copy text: ', err);
 | |
|       });
 | |
|     } else {
 | |
|       console.error('Target element not found');
 | |
|     }
 | |
|   });
 | |
| });
 |