From 42064c66b0bab0159f67821bf7fd41aae8ab8db7 Mon Sep 17 00:00:00 2001 From: Jake/Rads Date: Mon, 27 Jun 2022 13:08:19 +0200 Subject: [PATCH] feat(dashboard): add copy link button --- dashboard/src/lib/list/CardsList.svelte | 41 +++++++++++++++++++++++-- dashboard/src/lib/system/Main.svelte | 23 ++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/dashboard/src/lib/list/CardsList.svelte b/dashboard/src/lib/list/CardsList.svelte index 58b5464f..4b51732f 100644 --- a/dashboard/src/lib/list/CardsList.svelte +++ b/dashboard/src/lib/list/CardsList.svelte @@ -67,6 +67,38 @@ cardIndexArray[index].classList.remove("collapsed"); } } + + function getShortLink(id: string) { + let url = "https://pk.mt" + + if (itemType === "member") url += "/m/" + else if (itemType === "group") url += "/g/" + + url += id; + + return url; + } + + let copiedArray = []; + + async function copyShortLink(index: number, id: string, event?) { + if (event) { + if (event.key !== "Tab") event.preventDefault(); + event.stopPropagation(); + + let ctrlDown = event.ctrlKey||event.metaKey; // mac support + if (!(ctrlDown && event.key === "c") && event.key !== "Enter") return; + } + try { + await navigator.clipboard.writeText(getShortLink(id)); + + copiedArray[index] = true; + await new Promise(resolve => setTimeout(resolve, 2000)); + copiedArray[index] = false; + } catch (error) { + console.log(error); + } + } {#if settings && settings.accessibility ? (!settings.accessibility.expandedcards && !settings.accessibility.pagelinks) : true} @@ -76,7 +108,7 @@

@@ -108,7 +141,7 @@