| 512 | textArea.remove(); |
| 513 | |
| 514 | if (!copied) { |
| 515 | throw new Error("Copy is unavailable."); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | function showCopyFallback(button, text) { |
| 520 | const shareActions = button.closest(".share-actions"); |
| 521 | |
| 522 | if (!shareActions) { |
| 523 | showToast("Copy failed. Copying is unavailable in this browser."); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | let fallback = shareActions.querySelector(".copy-fallback"); |
| 528 | |
| 529 | if (!fallback) { |
| 530 | fallback = document.createElement("label"); |
| 531 | fallback.className = "copy-fallback"; |
| 532 | |
| 533 | const label = document.createElement("span"); |
| 534 | label.textContent = "Copy this post manually"; |
| 535 | |
| 536 | const textArea = document.createElement("textarea"); |
| 537 | textArea.setAttribute("readonly", ""); |
| 538 | textArea.rows = 4; |
| 539 | |
| 540 | fallback.append(label, textArea); |
| 541 | shareActions.append(fallback); |
| 542 | } |
| 543 | |
| 544 | const textArea = fallback.querySelector("textarea"); |
| 545 | textArea.value = text; |
| 546 | textArea.focus(); |
| 547 | textArea.select(); |