From ed9379dad715336cd0fd82de8937650588a7badf Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 28 Aug 2022 16:35:40 +0200 Subject: [PATCH] add copy functionality --- src/components/ShareModal.vue | 16 ++++++++++++---- src/locales/en.json | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/ShareModal.vue b/src/components/ShareModal.vue index 908c307b..87cdec60 100644 --- a/src/components/ShareModal.vue +++ b/src/components/ShareModal.vue @@ -14,7 +14,7 @@

@@ -68,10 +68,18 @@ export default { event.preventDefault(); }, followLink() { - window.location.href = this.generatedLink; + window.open(this.generatedLink, "_blank").focus(); }, - copyLink() { - this.$emit("close"); + async copyLink() { + await this.copyURL(this.generatedLink); + }, + async copyURL(mytext) { + try { + await navigator.clipboard.writeText(mytext); + alert(this.$t("info.copied")); + } catch ($e) { + alert(this.$t("info.cannot_copy")); + } }, }, computed: { diff --git a/src/locales/en.json b/src/locales/en.json index 028effbc..3eacdaa8 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -149,6 +149,8 @@ }, "info": { "preferences_note": "Note: preferences are saved in the local storage of your browser. Deleting your browser data will reset them.", - "page_not_found": "Page not found" + "page_not_found": "Page not found", + "copied": "Copied!", + "cannot_copy": "Can't copy!" } }