forked from XiaoMo/ChatGPT-Next-Web
fix(utils): 修复复制问题
This commit is contained in:
parent
bd7567fa85
commit
0af55366f1
28
app/utils.ts
28
app/utils.ts
@ -6,17 +6,23 @@ export function trimTopic(topic: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function copyToClipboard(text: string) {
|
export async function copyToClipboard(text: string) {
|
||||||
try {
|
if (navigator.clipboard) {
|
||||||
await navigator.clipboard.writeText(text);
|
navigator.clipboard.writeText(text).catch(err => {
|
||||||
} catch (error) {
|
console.error('Failed to copy: ', err);
|
||||||
const textarea = document.createElement("textarea");
|
});
|
||||||
textarea.value = text;
|
} else {
|
||||||
document.body.appendChild(textarea);
|
const textArea = document.createElement('textarea');
|
||||||
textarea.select();
|
textArea.value = text;
|
||||||
document.execCommand("copy");
|
document.body.appendChild(textArea);
|
||||||
document.body.removeChild(textarea);
|
textArea.focus();
|
||||||
} finally {
|
textArea.select();
|
||||||
showToast(Locale.Copy.Success);
|
try {
|
||||||
|
document.execCommand('copy');
|
||||||
|
console.log('Text copied to clipboard');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to copy: ', err);
|
||||||
|
}
|
||||||
|
document.body.removeChild(textArea);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user