From 0ff52104f59af9659705af999539c6dc02bf760d Mon Sep 17 00:00:00 2001 From: gaopw5 Date: Mon, 5 Aug 2024 23:51:32 +0800 Subject: [PATCH] feat(Copied): using replication in non-https environments --- core/src/comps/Copied.tsx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/comps/Copied.tsx b/core/src/comps/Copied.tsx index 88e4be34..9b88f744 100644 --- a/core/src/comps/Copied.tsx +++ b/core/src/comps/Copied.tsx @@ -41,7 +41,28 @@ export const Copied = (props: CopiedProps { + const textarea = document.createElement('textarea'); + textarea.style.position = 'absolute'; + textarea.style.opacity = '0'; + textarea.style.left = '-99999999px'; + textarea.value = text; + document.body.appendChild(textarea); + textarea.select(); + if (!document.execCommand('copy')) { + reject(); + } else { + reslove(); + } + textarea.remove(); + }); + }, + }; + + _clipboard .writeText(copyText) .then(() => { const timer = setTimeout(() => {