| 428 | const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); |
| 429 | |
| 430 | const copyToClipboard = (text) => { |
| 431 | if (navigator.clipboard && navigator.clipboard.writeText) { |
| 432 | navigator.clipboard.writeText(text).then(() => { |
| 433 | copyStatus.classList.remove('hidden'); |
| 434 | setTimeout(() => copyStatus.classList.add('hidden'), 2000); |
| 435 | }).catch(err => { |
| 436 | console.error('Failed to copy text: ', err); |
| 437 | }); |
| 438 | } else { |
| 439 | const textArea = document.createElement('textarea'); |
| 440 | textArea.value = text; |
| 441 | textArea.style.position = 'fixed'; |
| 442 | textArea.style.top = '0'; |
| 443 | textArea.style.left = '0'; |
| 444 | document.body.appendChild(textArea); |
| 445 | textArea.focus(); |
| 446 | textArea.select(); |
| 447 | |
| 448 | try { |
| 449 | const successful = document.execCommand('copy'); |
| 450 | if (successful) { |
| 451 | copyStatus.classList.remove('hidden'); |
| 452 | setTimeout(() => copyStatus.classList.add('hidden'), 2000); |
| 453 | } |
| 454 | } catch (err) { |
| 455 | console.error('Fallback: Oops, unable to copy', err); |
| 456 | } |
| 457 | |
| 458 | document.body.removeChild(textArea); |
| 459 | } |
| 460 | }; |
| 461 | }); |