feat: add export to .md button

This commit is contained in:
Yifei Zhang
2023-03-15 17:24:03 +00:00
parent 64e331a3e3
commit bab470d000
11 changed files with 181 additions and 18 deletions

View File

@@ -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);
}