|
1 | | -<!-- Code for version selectors --> |
| 1 | +<!-- Code for copy to clipboard button --> |
| 2 | +<script> |
| 3 | + document.addEventListener("DOMContentLoaded", function () { |
| 4 | + document.querySelectorAll('div.highlight').forEach(block => { |
| 5 | + // Create a wrapper for the button and message |
| 6 | + const wrapper = document.createElement('div'); |
| 7 | + wrapper.style = 'position:absolute;top:10px;right:10px;z-index:1;display:flex;align-items:center;gap:6px;'; |
| 8 | + |
| 9 | + // Create the copy button |
| 10 | + const button = document.createElement('button'); |
| 11 | + button.className = 'copy-button'; |
| 12 | + button.innerHTML = ` |
| 13 | + <svg viewBox="0 0 24 24" width="18" height="18" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 14 | + <path fill-rule="evenodd" clip-rule="evenodd" d="M21 8C21 6.34315 19.6569 5 18 5H10C8.34315 5 7 6.34315 7 8V20C7 21.6569 8.34315 23 10 23H18C19.6569 23 21 21.6569 21 20V8ZM19 8C19 7.44772 18.5523 7 18 7H10C9.44772 7 9 7.44772 9 8V20C9 20.5523 9.44772 21 10 21H18C18.5523 21 19 20.5523 19 20V8Z" fill="#0F0F0F"/> |
| 15 | + <path d="M6 3H16C16.5523 3 17 2.55228 17 2C17 1.44772 16.5523 1 16 1H6C4.34315 1 3 2.34315 3 4V18C3 18.5523 3.44772 19 4 19C4.55228 19 5 18.5523 5 18V4C5 3.44772 5.44772 3 6 3Z" fill="#0F0F0F"/> |
| 16 | + </svg> |
| 17 | + `; |
| 18 | + |
| 19 | + // Create the "Copied!" message span |
| 20 | + const message = document.createElement('span'); |
| 21 | + message.className = 'copied-message'; |
| 22 | + message.innerText = 'Copied to clipboard!'; |
| 23 | + message.style = 'opacity:0;transition:opacity 0.3s ease;font-size:0.75em;color:white;'; |
| 24 | + |
| 25 | + // Handle copy logic |
| 26 | + button.addEventListener('click', () => { |
| 27 | + const lines = block.querySelectorAll('span.cl'); |
| 28 | + const text = Array.from(lines).map(line => line.textContent).join(''); |
2 | 29 |
|
| 30 | + navigator.clipboard.writeText(text).then(() => { |
| 31 | + message.style.opacity = '1'; |
| 32 | + setTimeout(() => { |
| 33 | + message.style.opacity = '0'; |
| 34 | + }, 2000); |
| 35 | + }).catch(err => { |
| 36 | + console.error("Copy failed", err); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + // Append button and message |
| 41 | + wrapper.appendChild(message); |
| 42 | + wrapper.appendChild(button); |
| 43 | + block.style.position = 'relative'; |
| 44 | + block.appendChild(wrapper); |
| 45 | + }); |
| 46 | + }); |
| 47 | +</script> |
| 48 | + |
| 49 | + |
| 50 | +<!-- Code for version selectors --> |
3 | 51 | <script> |
4 | 52 | window.onload = function(){ |
5 | 53 | var currentUrl = window.location.href |
|
0 commit comments