()
| 1 | export default function copyCode() { |
| 2 | const buttons = Array.from(document.querySelectorAll('button.js-btn-copy')) |
| 3 | |
| 4 | if (!buttons) return |
| 5 | |
| 6 | buttons.forEach((button) => |
| 7 | button.addEventListener('click', async () => { |
| 8 | const text = (button as HTMLElement).dataset.clipboardText |
| 9 | if (!text) return |
| 10 | await navigator.clipboard.writeText(text) |
| 11 | |
| 12 | const beforeTooltip = button.getAttribute('aria-label') || '' |
| 13 | button.setAttribute('aria-label', 'Copied!') |
| 14 | |
| 15 | setTimeout(() => { |
| 16 | button.setAttribute('aria-label', beforeTooltip) |
| 17 | }, 2000) |
| 18 | }) |
| 19 | ) |
| 20 | } |
no outgoing calls
no test coverage detected