feat: 增加带格式的复制 (#182)
* feat: 增加带格式的复制 * feat: 移除前端超时设定 * chore: update deps * feat: 添加权限页面 * feat: 设定页面优化 * feat: 更新 chatgpt 以支持 `gpt-3.5-turbo-0301` * chore: version 2.9.0
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
// 转义 HTML 字符
|
||||
/**
|
||||
* 转义 HTML 字符
|
||||
* @param source
|
||||
*/
|
||||
export function encodeHTML(source: string) {
|
||||
return source
|
||||
.replace(/&/g, '&')
|
||||
@@ -8,17 +11,31 @@ export function encodeHTML(source: string) {
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
// 判断是否为代码块
|
||||
/**
|
||||
* 判断是否为代码块
|
||||
* @param text
|
||||
*/
|
||||
export function includeCode(text: string | null | undefined) {
|
||||
const regexp = /^(?:\s{4}|\t).+/gm
|
||||
return !!(text?.includes(' = ') || text?.match(regexp))
|
||||
}
|
||||
|
||||
// 复制文本
|
||||
export function copyText(text: string) {
|
||||
const input = document.createElement('input')
|
||||
/**
|
||||
* 复制文本
|
||||
* @param options
|
||||
*/
|
||||
export function copyText(options: { text: string; origin?: boolean }) {
|
||||
const props = { origin: true, ...options }
|
||||
|
||||
let input: HTMLInputElement | HTMLTextAreaElement
|
||||
|
||||
if (props.origin)
|
||||
input = document.createElement('textarea')
|
||||
else
|
||||
input = document.createElement('input')
|
||||
|
||||
input.setAttribute('readonly', 'readonly')
|
||||
input.setAttribute('value', text)
|
||||
input.value = props.text
|
||||
document.body.appendChild(input)
|
||||
input.select()
|
||||
if (document.execCommand('copy'))
|
||||
|
||||
Reference in New Issue
Block a user