(text)
| 13 | } |
| 14 | |
| 15 | export async function copyToClipboard(text) { |
| 16 | try { |
| 17 | if (navigator.clipboard && window.isSecureContext) { |
| 18 | await navigator.clipboard.writeText(text); |
| 19 | return true; |
| 20 | } |
| 21 | } catch (err) { |
| 22 | console.warn('Clipboard API failed, falling back to execCommand:', err); |
| 23 | } |
| 24 | |
| 25 | const textarea = document.createElement('textarea'); |
| 26 | textarea.value = text; |
| 27 | textarea.style.position = 'fixed'; |
| 28 | textarea.style.left = '-9999px'; |
| 29 | textarea.style.top = '-9999px'; |
| 30 | textarea.style.opacity = '0'; |
| 31 | document.body.appendChild(textarea); |
| 32 | textarea.select(); |
| 33 | |
| 34 | try { |
| 35 | const successful = document.execCommand('copy'); |
| 36 | document.body.removeChild(textarea); |
| 37 | return successful; |
| 38 | } catch (err) { |
| 39 | console.error('Failed to copy:', err); |
| 40 | document.body.removeChild(textarea); |
| 41 | return false; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | export function formatTime(timestamp) { |
| 46 | const date = new Date(timestamp); |
no outgoing calls
no test coverage detected