mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 07:10:16 +08:00
feat: add export to .md button
This commit is contained in:
21
app/utils.ts
21
app/utils.ts
@@ -9,3 +9,24 @@ export function trimTopic(topic: string) {
|
||||
|
||||
return s.join("");
|
||||
}
|
||||
|
||||
export function copyToClipboard(text: string) {
|
||||
navigator.clipboard.writeText(text).then(res => {
|
||||
alert('复制成功')
|
||||
}).catch(err => {
|
||||
alert('复制失败,请赋予剪切板权限')
|
||||
})
|
||||
}
|
||||
|
||||
export function downloadAs(text: string, filename: string) {
|
||||
const element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
||||
element.setAttribute('download', filename);
|
||||
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
|
||||
element.click();
|
||||
|
||||
document.body.removeChild(element);
|
||||
}
|
Reference in New Issue
Block a user