forked from XiaoMo/ChatGPT-Next-Web
fix: #513 show toast after copying
This commit is contained in:
parent
74cff2639b
commit
f3dbe5a251
20
app/utils.ts
20
app/utils.ts
@ -7,23 +7,21 @@ export function trimTopic(topic: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function copyToClipboard(text: string) {
|
export async function copyToClipboard(text: string) {
|
||||||
if (navigator.clipboard) {
|
try {
|
||||||
navigator.clipboard.writeText(text).catch(err => {
|
await navigator.clipboard.writeText(text);
|
||||||
console.error('Failed to copy: ', err);
|
} catch (error) {
|
||||||
});
|
const textArea = document.createElement("textarea");
|
||||||
} else {
|
|
||||||
const textArea = document.createElement('textarea');
|
|
||||||
textArea.value = text;
|
textArea.value = text;
|
||||||
document.body.appendChild(textArea);
|
document.body.appendChild(textArea);
|
||||||
textArea.focus();
|
textArea.focus();
|
||||||
textArea.select();
|
textArea.select();
|
||||||
try {
|
try {
|
||||||
document.execCommand('copy');
|
document.execCommand("copy");
|
||||||
console.log('Text copied to clipboard');
|
} catch (error) {
|
||||||
} catch (err) {
|
showToast(Locale.Copy.Failed);
|
||||||
console.error('Failed to copy: ', err);
|
|
||||||
}
|
}
|
||||||
document.body.removeChild(textArea);
|
} finally {
|
||||||
|
showToast(Locale.Copy.Success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user