| 87 | } |
| 88 | |
| 89 | async function copyText(text: string) { |
| 90 | if (navigator.clipboard?.writeText && window.isSecureContext) { |
| 91 | try { |
| 92 | await navigator.clipboard.writeText(text); |
| 93 | return true; |
| 94 | } catch { |
| 95 | // Continue to the textarea fallback below. |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | const textarea = document.createElement("textarea"); |
| 100 | textarea.value = text; |
| 101 | textarea.setAttribute("readonly", ""); |
| 102 | textarea.style.left = "-9999px"; |
| 103 | textarea.style.opacity = "0"; |
| 104 | textarea.style.position = "fixed"; |
| 105 | textarea.style.top = "0"; |
| 106 | document.body.appendChild(textarea); |
| 107 | textarea.focus(); |
| 108 | textarea.select(); |
| 109 | textarea.setSelectionRange(0, text.length); |
| 110 | try { |
| 111 | return document.execCommand("copy"); |
| 112 | } catch { |
| 113 | return false; |
| 114 | } finally { |
| 115 | document.body.removeChild(textarea); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | function isWeChat() { |
| 120 | return /MicroMessenger/i.test(navigator.userAgent); |