| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
|
|
| export async function copyToClipboard(text: string): Promise<boolean> {
|
|
|
|
|
|
|
| if (typeof navigator !== "undefined" && navigator.clipboard) {
|
| try {
|
| await navigator.clipboard.writeText(text);
|
| return true;
|
| } catch {
|
|
|
| }
|
| }
|
|
|
|
|
| if (typeof document !== "undefined" && document.body) {
|
| const textArea = document.createElement("textarea");
|
| textArea.value = text;
|
| textArea.style.cssText = "position:fixed;top:0;left:-9999px;opacity:0;pointer-events:none;";
|
| let appended = false;
|
|
|
| try {
|
| document.body.appendChild(textArea);
|
| appended = true;
|
| textArea.focus();
|
| textArea.select();
|
| return document.execCommand("copy");
|
| } catch {
|
| return false;
|
| } finally {
|
| if (appended && document.body.contains(textArea)) {
|
| document.body.removeChild(textArea);
|
| }
|
| }
|
| }
|
|
|
| return false;
|
| }
|
|
|