From 83750389f61dff13cb9bdf1d1b0c8be30fa3883c Mon Sep 17 00:00:00 2001 From: siroi <48815350+Gao-pw@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:03:18 +0800 Subject: [PATCH] feat(Copied): using replication in non-https environments (#56) Co-authored-by: gaopw5 --- 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(() => {