mirror of
https://github.com/LingChair/LingChair-V0.git
synced 2025-12-07 17:45:49 +08:00
fix(msg): 修复由于右键菜单获取的文本导致的HTML代码出错的问题
This commit is contained in:
@@ -638,12 +638,16 @@ class ChatMsgAdapter {
|
||||
while ($(ele).attr("tag") != "msg-card")
|
||||
ele = ele.parentNode
|
||||
e = $(ele)
|
||||
|
||||
let rawText = e.find("#raw-msg-content").text()
|
||||
let text = e.find("#msg-content").text()
|
||||
|
||||
let menuHtml = $.parseHTML(`<ul class="mdui-menu menu-on-message">
|
||||
<li class="mdui-menu-item">
|
||||
<a onclick="copyText(\`${e.find("#msg-content").text()}\`)" class="mdui-ripple">复制</a>
|
||||
<a onclick="copyText(CachedString.getAndRecycle('${CachedString.addToList(text)}'))" class="mdui-ripple">复制</a>
|
||||
</li>
|
||||
<li class="mdui-menu-item">
|
||||
<a onclick="mdui.alert(\`${e.find("#raw-msg-content").text()}\`, '消息原文', () => { }, { confirmText: '关闭' })" class="mdui-ripple">原文</a>
|
||||
<a onclick="mdui.alert(CachedString.getAndRecycle('${CachedString.addToList(rawText)}'), '消息原文', () => { }, { confirmText: '关闭' })" class="mdui-ripple">原文</a>
|
||||
</li>
|
||||
<li class="mdui-menu-item">
|
||||
<a onclick="mdui.alert('未制作功能', '提示', () => { }, { confirmText: '关闭' })" class="mdui-ripple">转发</a>
|
||||
|
||||
@@ -208,6 +208,45 @@ class Hash {
|
||||
}
|
||||
}
|
||||
|
||||
class CachedString {
|
||||
static cache = {}
|
||||
/**
|
||||
* 添加缓存文本
|
||||
* @param {String} 欲缓存的文本
|
||||
* @returns {String} 该文本的ID
|
||||
*/
|
||||
static addToList(str) {
|
||||
let id = Hash.sha256(str)
|
||||
this.cache[id] = str
|
||||
return id
|
||||
}
|
||||
/**
|
||||
* 回收字符
|
||||
* @param {String} 该文本的ID
|
||||
*/
|
||||
static recycle(id) {
|
||||
this.cache[id] = null
|
||||
}
|
||||
/**
|
||||
* 根据ID获取文本
|
||||
* @param {String} 该文本的ID
|
||||
* @returns {String} 文本
|
||||
*/
|
||||
static get(id) {
|
||||
return this.cache[id]
|
||||
}
|
||||
/**
|
||||
* 根据ID获取文本并回收
|
||||
* @param {String} 该文本的ID
|
||||
* @returns {String} 文本
|
||||
*/
|
||||
static getAndRecycle(id) {
|
||||
let t = this.get(id)
|
||||
this.recycle(id)
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
||||
window.copyText = copyText
|
||||
window.NData = NData
|
||||
window.escapeHTML = escapeHTML
|
||||
@@ -216,3 +255,4 @@ window.checkEmpty = checkEmpty
|
||||
window.sleep = sleep
|
||||
window.Hash = Hash
|
||||
window.通知 = 通知
|
||||
window.CachedString = CachedString
|
||||
|
||||
Reference in New Issue
Block a user