forked from XiaoMo/ChatGPT-Next-Web
fix: #366 use fallback copy
This commit is contained in:
parent
f863a562a0
commit
73865651a0
22
app/utils.ts
22
app/utils.ts
@ -5,15 +5,19 @@ export function trimTopic(topic: string) {
|
|||||||
return topic.replace(/[,。!?、,.!?]*$/, "");
|
return topic.replace(/[,。!?、,.!?]*$/, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function copyToClipboard(text: string) {
|
export async function copyToClipboard(text: string) {
|
||||||
navigator.clipboard
|
try {
|
||||||
.writeText(text)
|
await navigator.clipboard.writeText(text);
|
||||||
.then((res) => {
|
} catch (error) {
|
||||||
showToast(Locale.Copy.Success);
|
const textarea = document.createElement("textarea");
|
||||||
})
|
textarea.value = text;
|
||||||
.catch((err) => {
|
document.body.appendChild(textarea);
|
||||||
showToast(Locale.Copy.Failed);
|
textarea.select();
|
||||||
});
|
document.execCommand("copy");
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
} finally {
|
||||||
|
showToast(Locale.Copy.Success);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function downloadAs(text: string, filename: string) {
|
export function downloadAs(text: string, filename: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user