2023-03-10 18:25:33 +00:00
|
|
|
export function trimTopic(topic: string) {
|
2023-03-19 16:29:09 +00:00
|
|
|
const s = topic.split("");
|
2023-03-10 18:25:33 +00:00
|
|
|
let lastChar = s.at(-1); // 获取 s 的最后一个字符
|
|
|
|
let pattern = /[,。!?、]/; // 定义匹配中文标点符号的正则表达式
|
|
|
|
while (lastChar && pattern.test(lastChar!)) {
|
|
|
|
s.pop();
|
|
|
|
lastChar = s.at(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.join("");
|
|
|
|
}
|
2023-03-15 17:24:03 +00:00
|
|
|
|
|
|
|
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);
|
2023-03-19 14:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isIOS() {
|
|
|
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
|
|
return /iphone|ipad|ipod/.test(userAgent);
|
2023-03-15 17:24:03 +00:00
|
|
|
}
|