Browse Source

Update utils.ts

Yifei Zhang 2 years ago
parent
commit
905bf41cd8
1 changed files with 3 additions and 2 deletions
  1. 3 2
      app/utils.ts

+ 3 - 2
app/utils.ts

@@ -9,6 +9,7 @@ export function trimTopic(topic: string) {
 export async function copyToClipboard(text: string) {
   try {
     await navigator.clipboard.writeText(text);
+    showToast(Locale.Copy.Success);
   } catch (error) {
     const textArea = document.createElement("textarea");
     textArea.value = text;
@@ -17,11 +18,11 @@ export async function copyToClipboard(text: string) {
     textArea.select();
     try {
       document.execCommand("copy");
+      showToast(Locale.Copy.Success);
     } catch (error) {
       showToast(Locale.Copy.Failed);
     }
-  } finally {
-    showToast(Locale.Copy.Success);
+    document.body.removeChild(textArea);
   }
 }