|
|
@@ -0,0 +1,17 @@
|
|
|
+export async function copyToClipboard(text: string): Promise<boolean> {
|
|
|
+ try {
|
|
|
+ if (navigator.clipboard?.writeText) {
|
|
|
+ await navigator.clipboard.writeText(text);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch {}
|
|
|
+ const textarea = document.createElement('textarea');
|
|
|
+ textarea.value = text;
|
|
|
+ textarea.style.position = 'fixed';
|
|
|
+ textarea.style.opacity = '0';
|
|
|
+ document.body.appendChild(textarea);
|
|
|
+ textarea.select();
|
|
|
+ const ok = document.execCommand('copy');
|
|
|
+ document.body.removeChild(textarea);
|
|
|
+ return ok;
|
|
|
+}
|