mirror of
https://github.com/LingChair/LingChair-V0.git
synced 2025-12-08 10:05:49 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a5afc8ad0 | ||
|
|
4bdfad340f | ||
|
|
6ac1b460bb | ||
|
|
29e224f87a | ||
|
|
a39973bb5c | ||
|
|
47afacbba3 | ||
|
|
3a4d733c13 | ||
|
|
89263e6e2a | ||
|
|
b2c8c86689 | ||
|
|
6654141c18 | ||
|
|
822a4ad4da |
@@ -79,7 +79,13 @@
|
|||||||
|
|
||||||
.chat-message-left > .avatar,
|
.chat-message-left > .avatar,
|
||||||
.chat-message-right > .avatar {
|
.chat-message-right > .avatar {
|
||||||
width: 45px;
|
width: 50px;
|
||||||
height: 45px;
|
height: 50px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message-image {
|
||||||
|
max-width: 40%;
|
||||||
|
max-height: 40%;
|
||||||
|
border-radius: 15px;
|
||||||
|
}
|
||||||
|
|||||||
97
ling_chair_http/finally.js
Normal file
97
ling_chair_http/finally.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* ©2024 满月叶
|
||||||
|
* Github: MoonLeeeaf
|
||||||
|
* 最终执行的杂项
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 感觉 window.attr 比那一堆 import 好用多了
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// 正文开始
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
// 没有刷新令牌需要重新登录 或者初始化
|
||||||
|
if (!localStorage.refreshToken || localStorage.refreshToken === "")
|
||||||
|
localStorage.isSignIn = false
|
||||||
|
|
||||||
|
if (!localStorage.server || localStorage.server === "")
|
||||||
|
setUpClient()
|
||||||
|
else
|
||||||
|
setUpClient(localStorage.server)
|
||||||
|
|
||||||
|
// 登录到账号
|
||||||
|
let dialogSignIn
|
||||||
|
// 谨防 localStorage 字符串数据大坑
|
||||||
|
if (localStorage.isSignIn == "false")
|
||||||
|
dialogSignIn = new mdui.Dialog(viewBinding.dialogSignIn.get(0), {
|
||||||
|
modal: true,
|
||||||
|
closeOnEsc: false,
|
||||||
|
history: false,
|
||||||
|
}).open()
|
||||||
|
else {
|
||||||
|
(async () => viewBinding.userNick.text(await NickCache.getNick(localStorage.userName)))()
|
||||||
|
let hello
|
||||||
|
let nowHour = new Date().getHours()
|
||||||
|
if (nowHour >= 6 && nowHour <= 11) hello = "早安"
|
||||||
|
else if (nowHour == 12) hello = "中午好"
|
||||||
|
else if (nowHour >= 13 && nowHour <= 18) hello = "下午好"
|
||||||
|
else if (nowHour >= 19 && nowHour < 22) hello = "晚上好"
|
||||||
|
else hello = "晚安"
|
||||||
|
viewBinding.helloText.text(hello)
|
||||||
|
|
||||||
|
viewBinding.userHead.attr("src", CurrentUser.getUserHeadUrl(localStorage.userName))
|
||||||
|
|
||||||
|
ContactsList.reloadList()
|
||||||
|
|
||||||
|
CurrentUser.registerCallback()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 感谢AI的力量
|
||||||
|
Stickyfill.add($("*").filter((a, b) => $(b).css('position') === 'sticky'))
|
||||||
|
|
||||||
|
ChatMsgAdapter.initMsgElementEvents()
|
||||||
|
|
||||||
|
ChatMsgAdapter.initInputResizer()
|
||||||
|
|
||||||
|
const showLinkDialog = (link) => mdui.alert(decodeURI(link) + "<br/>如果你确认此链接是安全的, 那么请<a class=\"mdui-text-color-theme-accent\" href=\"" + link + "\">点我</a>", '链接', () => { }, { confirmText: "关闭" })
|
||||||
|
|
||||||
|
const showImageDialog = (link, id, alt) => mdui.alert(`此图片链接来源未知: ${decodeURI(link)}<br/>如果你希望加载, 请<a class="mdui-text-color-theme-accent" mdui-dialog-close onclick="$('#${id}').html('<img src=\\'${link}\\' alt=\\'${decodeURI(alt)}\\' class=\\'message-image\\'></img>')">点我</a>`, '外部图片', () => { }, { confirmText: "关闭" })
|
||||||
|
|
||||||
|
const showCodeDialog = (code) => mdui.alert(`<pre><code>${decodeURI(code)}</code></pre>`, '代码块', () => { }, { confirmText: "关闭" })
|
||||||
|
|
||||||
|
const renderer = {
|
||||||
|
heading(text, level) {
|
||||||
|
return text
|
||||||
|
},
|
||||||
|
paragraph(text) {
|
||||||
|
return text
|
||||||
|
},
|
||||||
|
blockquote(text) {
|
||||||
|
return text
|
||||||
|
},
|
||||||
|
link(href, title, text) {
|
||||||
|
return `<a class="mdui-text-color-theme-accent" onclick="showLinkDialog('${encodeURI(href)}')">[链接] ${text}</a>`
|
||||||
|
},
|
||||||
|
image(href, title, text) {
|
||||||
|
let h = Hash.sha256(href)
|
||||||
|
let out = true
|
||||||
|
try {
|
||||||
|
out = new URL(href).hostname === new URL(location.href)
|
||||||
|
} catch(e) {}
|
||||||
|
if (out)
|
||||||
|
return `<img src="${encodeURI(href)}" alt="${text}" class="message-image"></img>`
|
||||||
|
else
|
||||||
|
return `<div id="${h}"><a class="mdui-text-color-theme-accent" onclick="showImageDialog('${encodeURI(href)}', '${h}', '${encodeURI(text)}')">[外部图片] ${text}</a></div>`
|
||||||
|
},
|
||||||
|
code(src) {
|
||||||
|
return `<a class="mdui-text-color-theme-accent" onclick="showCodeDialog(\`${encodeURI(src)}\`)">[代码块]</a>`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
marked.use({
|
||||||
|
gfm: true,
|
||||||
|
renderer: renderer,
|
||||||
|
async: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
573
ling_chair_http/handler.js
Normal file
573
ling_chair_http/handler.js
Normal file
@@ -0,0 +1,573 @@
|
|||||||
|
/*
|
||||||
|
* ©2024 满月叶
|
||||||
|
* Github: MoonLeeeaf
|
||||||
|
* 业务逻辑
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// 当前用户
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
class CurrentUser {
|
||||||
|
static myAccessToken
|
||||||
|
/**
|
||||||
|
* 登录账号
|
||||||
|
* @param {String} name
|
||||||
|
* @param {String} passwd
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
static signIn(name, passwd, cb) {
|
||||||
|
client.emit("user.signIn", {
|
||||||
|
name: name,
|
||||||
|
passwd: Hash.sha256(passwd) + Hash.md5(passwd),
|
||||||
|
}, (re) => {
|
||||||
|
if (re.code !== 0)
|
||||||
|
return mdui.snackbar(re.msg)
|
||||||
|
|
||||||
|
cb(re)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 注册账号
|
||||||
|
* @param {String} name
|
||||||
|
* @param {String} passwd
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
static signUp(name, passwd, cb) {
|
||||||
|
client.emit("user.signUp", {
|
||||||
|
name: name,
|
||||||
|
passwd: Hash.sha256(passwd) + Hash.md5(passwd),
|
||||||
|
}, (re) => {
|
||||||
|
if (re.code !== 0)
|
||||||
|
return mdui.snackbar(re.msg)
|
||||||
|
|
||||||
|
cb(re)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 登录对话框中的登录逻辑
|
||||||
|
* @param {String} name
|
||||||
|
* @param {String} passwd
|
||||||
|
*/
|
||||||
|
static signInWithDialog(name, passwd) {
|
||||||
|
this.signIn(name, passwd, (re) => {
|
||||||
|
localStorage.refreshToken = re.data.refreshToken
|
||||||
|
localStorage.isSignIn = true
|
||||||
|
|
||||||
|
location.reload()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 设置昵称
|
||||||
|
* @param {String} nick
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
static async setNick(nick, cb) {
|
||||||
|
client.emit("user.setNick", {
|
||||||
|
name: localStorage.userName,
|
||||||
|
accessToken: await this.getAccessToken(),
|
||||||
|
nick: nick,
|
||||||
|
}, (re) => {
|
||||||
|
if (re.code !== 0)
|
||||||
|
return mdui.snackbar(re.msg)
|
||||||
|
if (cb) cb()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取用户头像的链接
|
||||||
|
* @param {String} name
|
||||||
|
* @returns {String} headImageUrl
|
||||||
|
*/
|
||||||
|
static getUserHeadUrl(name) {
|
||||||
|
return client.io.uri + "/users_head/" + name + ".png"
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取访问密钥
|
||||||
|
* @param {String} name
|
||||||
|
* @returns {Promise<String>} accessToken
|
||||||
|
*/
|
||||||
|
static async getAccessToken(er) {
|
||||||
|
if (this.myAccessToken == null)
|
||||||
|
this.myAccessToken = await new Promise((res) => {
|
||||||
|
client.emit("user.getAccessToken", { name: localStorage.userName, refreshToken: localStorage.refreshToken }, (r) => {
|
||||||
|
if (r.data != null) res(r.data.accessToken)
|
||||||
|
if (er != null) er(r.msg)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return this.myAccessToken
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 请求上传头像
|
||||||
|
*/
|
||||||
|
static uploadHeadImage() {
|
||||||
|
viewBinding.uploadHeadImage.click()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 上传头像回调事件
|
||||||
|
* @param {Element} element
|
||||||
|
*/
|
||||||
|
static async uploadHeadImageCallback(self) {
|
||||||
|
let img = self.files[0]
|
||||||
|
client.emit("user.setHeadImage", {
|
||||||
|
name: localStorage.userName,
|
||||||
|
accessToken: await CurrentUser.getAccessToken(),
|
||||||
|
headImage: img,
|
||||||
|
}, (re) => mdui.snackbar(re.msg))
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 验证用户
|
||||||
|
*/
|
||||||
|
static auth() {
|
||||||
|
client.emit("user.auth", { name: localStorage.userName, refreshToken: localStorage.refreshToken }, (re) => {
|
||||||
|
if (re.code !== 0) {
|
||||||
|
console.error(re)
|
||||||
|
if (!re.invalid)
|
||||||
|
return mdui.snackbar("验证用户失败!")
|
||||||
|
|
||||||
|
mdui.alert("账号刷新令牌已过期, 请重新登录哦", "提示", () => CurrentUser.signOutAndReload(), {
|
||||||
|
confirmText: "确定",
|
||||||
|
closeOnConfirm: false,
|
||||||
|
closeOnEsc: false,
|
||||||
|
modal: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 登出并重载页面
|
||||||
|
*/
|
||||||
|
static signOutAndReload() {
|
||||||
|
localStorage.refreshToken = ""
|
||||||
|
localStorage.isSignIn = false
|
||||||
|
|
||||||
|
setTimeout(() => location.reload(), 300)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 注册客户端回调事件
|
||||||
|
*/
|
||||||
|
static registerCallback() {
|
||||||
|
client.on("msg.receive", async (a) => {
|
||||||
|
if (checkEmpty([a.target, a.msg, a.type]))
|
||||||
|
return
|
||||||
|
|
||||||
|
if ((ChatMsgAdapter.target === a.target) && (ChatMsgAdapter.type === a.type)) {
|
||||||
|
let i = ChatMsgAdapter.isAtBottom()
|
||||||
|
await ChatMsgAdapter.addMsg(a.target, a.msg.msg, a.msg.time)
|
||||||
|
if (i) ChatMsgAdapter.scrollToBottom()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ChatMsgAdapter.target !== localStorage.userName) {
|
||||||
|
let n = new 通知().setTitle("" + await NickCache.getNick(a.target)).setMessage(a.msg.msg).setIcon(CurrentUser.getUserHeadUrl(a.target)).show(async () => {
|
||||||
|
await ChatMsgAdapter.switchTo(a.target, a.type)
|
||||||
|
location.replace("#msgid_" + a.msg.msgid)
|
||||||
|
n.close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 打开资料卡
|
||||||
|
* @param {String} name
|
||||||
|
*/
|
||||||
|
static async openProfileDialog(name) {
|
||||||
|
viewBinding.dialogProfileHead.attr("src", CurrentUser.getUserHeadUrl(name))
|
||||||
|
viewBinding.dialogProfileNick.text(await NickCache.getNick(name))
|
||||||
|
new mdui.Dialog(viewBinding.dialogProfile).open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================
|
||||||
|
// 昵称缓存
|
||||||
|
// ================================
|
||||||
|
|
||||||
|
class NickCache {
|
||||||
|
static data = {}
|
||||||
|
/**
|
||||||
|
* 获取昵称
|
||||||
|
* @param {String} name
|
||||||
|
* @returns {String} nick
|
||||||
|
*/
|
||||||
|
static async getNick(name) {
|
||||||
|
return await new Promise((res, rej) => {
|
||||||
|
// 这个this别摆着不放啊 不然两下就会去世
|
||||||
|
let nick = this.data[name]
|
||||||
|
if (nick == null)
|
||||||
|
client.emit("user.getNick", { name: localStorage.userName }, (re) => {
|
||||||
|
let nk = re.data != null ? re.data.nick : name
|
||||||
|
if (nk == null) nk = name
|
||||||
|
this.data[name] = nk
|
||||||
|
res(nk)
|
||||||
|
})
|
||||||
|
else
|
||||||
|
res(nick)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ContactsList {
|
||||||
|
/**
|
||||||
|
* 重载联系人列表
|
||||||
|
*/
|
||||||
|
static async reloadList() {
|
||||||
|
client.emit("user.getFriends", {
|
||||||
|
name: localStorage.userName,
|
||||||
|
accessToken: await CurrentUser.getAccessToken(),
|
||||||
|
}, async (re) => {
|
||||||
|
if (re.code !== 0)
|
||||||
|
return mdui.snackbar(re.msg)
|
||||||
|
|
||||||
|
viewBinding.contactsList.empty()
|
||||||
|
let ls = re.data.friends
|
||||||
|
for (let index in ls) {
|
||||||
|
let name = ls[index]
|
||||||
|
let dick = await NickCache.getNick(name)
|
||||||
|
$($.parseHTML(`<li class="mdui-list-item mdui-ripple" mdui-drawer-close><div class="mdui-list-item-avatar"><img src="` + CurrentUser.getUserHeadUrl(name) + `" onerror="this.src='res/default_head.png'" /></div><div class="mdui-list-item-content">` + dick + `</div></li>`)).appendTo(viewBinding.contactsList).click(() => {
|
||||||
|
ChatMsgAdapter.switchTo(name, "single")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 添加联系人/群峦
|
||||||
|
* @param {String} nameOrId
|
||||||
|
*/
|
||||||
|
static add(name, type) {
|
||||||
|
if (type == "single") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 打开添加联系人的对话框
|
||||||
|
*/
|
||||||
|
static openAddDialog() {
|
||||||
|
new mdui.Dialog(viewBinding.dialogNewContact.get(0)).open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消息核心
|
||||||
|
|
||||||
|
class ChatPage {
|
||||||
|
static cached = {}
|
||||||
|
constructor(name, type) {
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 切换到某一个聊天对象
|
||||||
|
* @param {String} name
|
||||||
|
* @param {String} type
|
||||||
|
*/
|
||||||
|
static switchTo(name, type) {
|
||||||
|
if (!this.cached[name])
|
||||||
|
this.cached[name] = new ChatPage(name, type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChatMsgAdapter {
|
||||||
|
static type
|
||||||
|
static target
|
||||||
|
static minMsgId
|
||||||
|
static time
|
||||||
|
static minutesCache
|
||||||
|
static resizeDick
|
||||||
|
/**
|
||||||
|
* 切换到某一个聊天对象
|
||||||
|
* @param {String} name
|
||||||
|
* @param {String} type
|
||||||
|
*/
|
||||||
|
static async switchTo(name, type) {
|
||||||
|
viewBinding.tabChatSeesion.show()
|
||||||
|
viewBinding.tabChatSeesion.text(await NickCache.getNick(name))
|
||||||
|
viewBinding.tabChatSeesion.get(0).click()
|
||||||
|
|
||||||
|
this.type = type
|
||||||
|
this.target = name
|
||||||
|
this.minMsgId = null
|
||||||
|
|
||||||
|
viewBinding.pageChatSeesion.empty()
|
||||||
|
|
||||||
|
await this.loadMore()
|
||||||
|
this.scrollToBottom()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 发送消息
|
||||||
|
* @param {String} msg
|
||||||
|
*/
|
||||||
|
static async send(msg) {
|
||||||
|
client.emit("user.sendSingleMsg", {
|
||||||
|
name: localStorage.userName,
|
||||||
|
target: this.target,
|
||||||
|
msg: msg,
|
||||||
|
accessToken: await CurrentUser.getAccessToken(),
|
||||||
|
}, async (re) => {
|
||||||
|
if (re.code !== 0)
|
||||||
|
return mdui.snackbar(re.msg)
|
||||||
|
|
||||||
|
viewBinding.inputMsg.val("")
|
||||||
|
|
||||||
|
// 微机课闲的没事干玩玩 发现私聊会多发一个(一个是本地的, 另一个是发送成功的) 选择一个关掉就好了
|
||||||
|
// 这里我选择服务端不发送回调, 不然多设备同步会吵死
|
||||||
|
// 错了 应该是客户端少发条才对 不然不能多设备同步
|
||||||
|
if ((ChatMsgAdapter.target !== localStorage.userName) && ChatMsgAdapter.type === "single") {
|
||||||
|
let i = ChatMsgAdapter.isAtBottom()
|
||||||
|
await ChatMsgAdapter.addMsg(localStorage.userName, msg, re.data.time, re.data.msgid)
|
||||||
|
if (i) ChatMsgAdapter.scrollToBottom()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取聊天消息记录
|
||||||
|
* @param {int} 起始点
|
||||||
|
* @param {int} 获取数量
|
||||||
|
*/
|
||||||
|
static async getHistroy(start, limit) {
|
||||||
|
return new Promise(async (res, rej) => {
|
||||||
|
client.emit("user.getSingleChatHistroy", {
|
||||||
|
name: localStorage.userName,
|
||||||
|
target: this.target,
|
||||||
|
limit: limit,
|
||||||
|
accessToken: await CurrentUser.getAccessToken(),
|
||||||
|
startId: start,
|
||||||
|
}, (re) => {
|
||||||
|
if (re.code !== 0)
|
||||||
|
return mdui.snackbar(re.msg)
|
||||||
|
res(re.data.histroy)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 加载更多聊天记录
|
||||||
|
* @param {int}} 加载数量
|
||||||
|
*/
|
||||||
|
static async loadMore(limit) {
|
||||||
|
let histroy = await this.getHistroy(this.minMsgId, limit == null ? 13 : limit)
|
||||||
|
|
||||||
|
if (histroy.length == 0)
|
||||||
|
return mdui.snackbar("已经加载完了~")
|
||||||
|
|
||||||
|
let re = this.minMsgId != null
|
||||||
|
this.minMsgId = histroy[0].msgid - 1
|
||||||
|
let sc = 0
|
||||||
|
if (re) histroy = histroy.reverse()
|
||||||
|
for (let index in histroy) {
|
||||||
|
let i = histroy[index]
|
||||||
|
let e = await this.addMsg(i.name, i.msg, i.time, re, i.msgid)
|
||||||
|
// 因为某些因素直接DEBUG到吐血 断点继续都不报错 原因不明
|
||||||
|
sc = sc + (e == null ? 25 : e.get(0).offsetTop)
|
||||||
|
}
|
||||||
|
window.scrollBy({
|
||||||
|
top: sc,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 添加系统消息
|
||||||
|
* @param {String} 消息
|
||||||
|
* @param {String} 是否加到顶部
|
||||||
|
* @returns {jQuery} 消息元素
|
||||||
|
*/
|
||||||
|
static addSystemMsg(m, re) {
|
||||||
|
let e
|
||||||
|
if (re)
|
||||||
|
// 加到头部
|
||||||
|
e = $($.parseHTML(m)).prependTo(viewBinding.pageChatSeesion)
|
||||||
|
else
|
||||||
|
// 加到尾部
|
||||||
|
e = $($.parseHTML(m)).appendTo(viewBinding.pageChatSeesion)
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 是否在底部
|
||||||
|
* @returns {Boolean} 是否在底部
|
||||||
|
*/
|
||||||
|
static isAtBottom() {
|
||||||
|
let elementRect = viewBinding.pageChatSeesion.get(0).getBoundingClientRect()
|
||||||
|
return (elementRect.bottom <= window.innerHeight)
|
||||||
|
}
|
||||||
|
// 添加消息 返回消息的JQ对象
|
||||||
|
// name: 用户id m: 消息 t: 时间戳 re: 默认加到尾部 msgid: 消息id
|
||||||
|
/**
|
||||||
|
* 添加聊天记录
|
||||||
|
* @param {String} name
|
||||||
|
* @param {String} msg
|
||||||
|
* @param {String} type
|
||||||
|
* @param {String} 是否加到头部
|
||||||
|
* @param {String || int} 消息id
|
||||||
|
* @returns {jQuery} 消息元素
|
||||||
|
*/
|
||||||
|
static async addMsg(name, preMsg, time, addToTop, msgid) {
|
||||||
|
|
||||||
|
let nick = await NickCache.getNick(name) // re.data == null ? name : re.data.nick
|
||||||
|
|
||||||
|
let msg
|
||||||
|
|
||||||
|
try {
|
||||||
|
msg = await marked.parse(preMsg)
|
||||||
|
} catch(error) {
|
||||||
|
console.log("解析消息失败: " + error)
|
||||||
|
msg = escapeHTML(preMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
let temp
|
||||||
|
if (name === localStorage.userName)
|
||||||
|
temp = `<div class="chat-message-right">
|
||||||
|
<div class="message-content-with-nickname-right">
|
||||||
|
<span class="nickname">${ nick }</span>
|
||||||
|
<div class="message-content mdui-card" tag="msg-card" id="msgid_${ msgid }">
|
||||||
|
<span id="msg-content">${ msg }</span>
|
||||||
|
<pre class="mdui-hidden" id="raw-msg-content">${ preMsg }</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<img class="avatar" src="${ CurrentUser.getUserHeadUrl(name) }" onerror="this.src='res/default_head.png'" />
|
||||||
|
</div>`
|
||||||
|
else
|
||||||
|
temp = `<div class="chat-message-left">
|
||||||
|
<img class="avatar" src="${ CurrentUser.getUserHeadUrl(name) }" onerror="this.src='res/default_head.png'" />
|
||||||
|
<div class="message-content-with-nickname-left">
|
||||||
|
<span class="nickname">${ nick }</span>
|
||||||
|
<div class="message-content mdui-card" tag="msg-card" id="msgid_${ msgid }">
|
||||||
|
<span id="msg-content">${ msg }</span>
|
||||||
|
<pre class="mdui-hidden" id="raw-msg-content">${ preMsg }</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
|
||||||
|
let nowMinutes = new Date(time).getMinutes()
|
||||||
|
let msgElement
|
||||||
|
if (addToTop) {
|
||||||
|
this.addSystemMsg(temp, addToTop)
|
||||||
|
if (this.minutesCache != nowMinutes) {
|
||||||
|
msgElement = this.addSystemMsg(`<div class="mdui-center">` + new Date().format(time == null ? Date.parse("1000-1-1 00:00:00") : time, "yyyy年MM月dd日 hh:mm:ss") + `</div>`, addToTop)
|
||||||
|
this.time = nowMinutes
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.minutesCache != nowMinutes) {
|
||||||
|
msgElement = this.addSystemMsg(`<div class="mdui-center">` + new Date().format(time == null ? Date.parse("1000-1-1 00:00:00") : time, "yyyy年MM月dd日 hh:mm:ss") + `</div>`, addToTop)
|
||||||
|
this.time = nowMinutes
|
||||||
|
}
|
||||||
|
this.addSystemMsg(temp, addToTop)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.minutesCache = new Date(time).getMinutes()
|
||||||
|
|
||||||
|
return msgElement
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 从服务器加载一些聊天记录
|
||||||
|
* @param {int} 数量
|
||||||
|
*/
|
||||||
|
static async loadMsgs(limit) {
|
||||||
|
let histroy = await this.getHistroy(this.msgList[0] == null ? null : this.msgList[0].msgid - 1, limit == null ? 13 : limit)
|
||||||
|
this.msgList = histroy
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 滑到底部
|
||||||
|
*/
|
||||||
|
static scrollToBottom() {
|
||||||
|
// 吐了啊 原来这样就行了 我何必在子element去整啊
|
||||||
|
viewBinding.chatPager.get(0).scrollBy({
|
||||||
|
top: 1145141919810,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 初始化输入框位置调整器
|
||||||
|
*/
|
||||||
|
static initInputResizer() {
|
||||||
|
// 实验表面移动端切出输入法时会触发1-2次resize事件
|
||||||
|
// 可以利用这个特性来实现自动滚动文本
|
||||||
|
let resize = () => {
|
||||||
|
// CSS 牵一发而动全身 因此这个减少的数值是每天都要更改的
|
||||||
|
viewBinding.pageChatSeesion.height(window.innerHeight - viewBinding.inputToolbar.height() - $("header.mdui-appbar").height() - viewBinding.chatTab.height() - 65)
|
||||||
|
let ledi = this.resizeDick - window.innerHeight
|
||||||
|
if (isMobile()) viewBinding.chatPager.get(0).scrollBy({
|
||||||
|
// 5.19晚10:56分调配出来的秘方
|
||||||
|
// < 0 为窗口变大
|
||||||
|
// cnm的,调试十万次就你tm检测不到底是吧,就你语法天天错误是吧
|
||||||
|
// 欺负我现在用不了电脑
|
||||||
|
top: -(ledi) * ((ledi < 0 && this.isAtBottom()) ? 6 : -1), // (ledi < 0 ? 6 : 6),
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
this.resizeDick = window.innerHeight
|
||||||
|
}
|
||||||
|
window.initInputResizerResize = resize
|
||||||
|
window.addEventListener("resize", resize)
|
||||||
|
resize()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 初始化消息框右击事件
|
||||||
|
*/
|
||||||
|
static initMsgElementEvents() {
|
||||||
|
let listeners = {}
|
||||||
|
let menu
|
||||||
|
let callback = (e) => {
|
||||||
|
if (menu) menu.close()
|
||||||
|
// 切到 div.message-content
|
||||||
|
let ele = e.get(0)
|
||||||
|
while ($(ele).attr("tag") != "msg-card")
|
||||||
|
ele = ele.parentNode
|
||||||
|
e = $(ele)
|
||||||
|
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>
|
||||||
|
</li>
|
||||||
|
<li class="mdui-menu-item">
|
||||||
|
<a onclick="mdui.alert(\`${ e.find("#raw-msg-content").text() }\`, '消息原文', () => { }, { confirmText: '关闭' })" class="mdui-ripple">原文</a>
|
||||||
|
</li>
|
||||||
|
<li class="mdui-menu-item">
|
||||||
|
<a onclick="mdui.alert('未制作功能', '提示', () => { }, { confirmText: '关闭' })" class="mdui-ripple">转发</a>
|
||||||
|
</li>
|
||||||
|
</ul>`)
|
||||||
|
let $menu = $(menuHtml)
|
||||||
|
e.before($menu)
|
||||||
|
menu = new mdui.Menu(e.get(0), menuHtml, {
|
||||||
|
position: "bottom",
|
||||||
|
align: "right",
|
||||||
|
// covered: true,
|
||||||
|
})
|
||||||
|
$menu.on('closed.mdui.menu', () => {
|
||||||
|
$(menuHtml).remove()
|
||||||
|
})
|
||||||
|
menu.open()
|
||||||
|
}
|
||||||
|
viewBinding.pageChatSeesion.on('contextmenu mousedown mouseup', '.message-content', (e) => {
|
||||||
|
let eventType = e.type
|
||||||
|
let self = $(e.target)
|
||||||
|
|
||||||
|
// 根据事件类型执行不同操作
|
||||||
|
switch (eventType) {
|
||||||
|
case 'contextmenu':
|
||||||
|
e.preventDefault() // 阻止默认行为
|
||||||
|
callback(self)
|
||||||
|
break
|
||||||
|
case 'mousedown':
|
||||||
|
if (!isMobile()) return
|
||||||
|
listeners[self + ""] = setTimeout(() => {
|
||||||
|
callback(self)
|
||||||
|
}, 300) // 300颗够吗 应该够吧
|
||||||
|
break
|
||||||
|
case 'mouseup':
|
||||||
|
if (!isMobile()) return
|
||||||
|
clearTimeout(listeners[self + ""])
|
||||||
|
listeners[self + ""] = null
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新联系人列表以及昵称缓存
|
||||||
|
*/
|
||||||
|
function refreshAll() {
|
||||||
|
ContactsList.reloadList()
|
||||||
|
delete NickCache.data
|
||||||
|
NickCache.data = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.User = CurrentUser
|
||||||
|
window.ContactsList = ContactsList
|
||||||
|
window.NickCache = NickCache
|
||||||
|
window.ChatPage = ChatPage
|
||||||
|
window.ChatMsgAdapter = ChatMsgAdapter
|
||||||
|
window.refreshAll = refreshAll
|
||||||
@@ -1,29 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* 铃之椅 - 把选择权还给用户, 让聊天权掌握在用户手中
|
* ©2024 满月叶
|
||||||
* Copyright 2024 满月叶
|
* Github: MoonLeeeaf
|
||||||
* GitHub: https://github.com/MoonLeeeaf/LingChair-Web-Client
|
* 铃之椅 网页端
|
||||||
* 本项目使用 Apache 2.0 协议开源
|
|
||||||
*
|
|
||||||
* Copyright 2024 MoonLeeeaf
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
html, body {
|
html, body {
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
/* overflow: hidden; */
|
overflow: hidden;
|
||||||
/*font: initial;*/
|
/*font: initial;*/
|
||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
@@ -49,6 +34,24 @@ body {
|
|||||||
position: sticky;
|
position: sticky;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
display: block;
|
display: block;
|
||||||
height: var(--pseudo-height); /* 设置伪元素的高度 */
|
}
|
||||||
z-index: -1; /* 防止遮挡实际内容 */
|
|
||||||
}
|
.chat-seesion {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* https://segmentfault.com/q/1010000010391524 */
|
||||||
|
img {
|
||||||
|
image-rendering: -moz-crisp-edges; /* Firefox */
|
||||||
|
image-rendering: -o-crisp-edges; /* Opera */
|
||||||
|
image-rendering: -webkit-optimize-contrast; /* Webkit (non-standard naming) */
|
||||||
|
image-rendering: crisp-edges;
|
||||||
|
-ms-interpolation-mode: nearest-neighbor; /* IE (non-standard property) */
|
||||||
|
}
|
||||||
|
|
||||||
|
img.round {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,26 +1,10 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="zh-cmn-Hans">
|
<html lang="zh-cmn-Hans">
|
||||||
<!--
|
<!--
|
||||||
* 铃之椅 - 把选择权还给用户, 让聊天权掌握在用户手中
|
* ©2024 满月叶
|
||||||
* Copyright 2024 满月叶
|
* Github: MoonLeeeaf
|
||||||
* GitHub: https://github.com/MoonLeeeaf/LingChair-Web-Client
|
* 铃之椅 网页端
|
||||||
* 本项目使用 Apache 2.0 协议开源
|
|
||||||
*
|
|
||||||
* Copyright 2024 MoonLeeeaf
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" />
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" />
|
||||||
@@ -41,6 +25,7 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/gh/wilddeer/stickyfill@2.1.0/dist/stickyfill.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/gh/wilddeer/stickyfill@2.1.0/dist/stickyfill.min.js"></script>
|
||||||
<script src="https://unpkg.com/jquery@3.7.1/dist/jquery.min.js"></script>
|
<script src="https://unpkg.com/jquery@3.7.1/dist/jquery.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||||
<link rel="icon" href="res/icon.ico" />
|
<link rel="icon" href="res/icon.ico" />
|
||||||
<title>铃之椅</title>
|
<title>铃之椅</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -147,13 +132,14 @@
|
|||||||
<div class="mdui-center" style="margin: 15px;"><a href="javascript:;" onclick="ChatMsgAdapter.loadMore()"
|
<div class="mdui-center" style="margin: 15px;"><a href="javascript:;" onclick="ChatMsgAdapter.loadMore()"
|
||||||
class="mdui-text-color-theme">加载更多</a> | <a href="javascript:;"
|
class="mdui-text-color-theme">加载更多</a> | <a href="javascript:;"
|
||||||
onclick="ChatMsgAdapter.scrollToBottom()" class="mdui-text-color-theme">回到底部</a></div>
|
onclick="ChatMsgAdapter.scrollToBottom()" class="mdui-text-color-theme">回到底部</a></div>
|
||||||
<div n-id="pageChatSeesion" style="flex: 1 1 auto;display: flex;flex-direction: column;position: relative;">
|
<div n-id="pageChatSeesion" class="chat-seesion">
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 输入框和聊天消息重叠的原因就是死人 scrollbar, 把自动调整的距离调小, margin调大就行了 -->
|
||||||
</div>
|
</div>
|
||||||
<!-- 妈的黑化了 私人玩意这么难整 早知道 z-index 弄死它得了 浪费我时间 我就没试过这么离谱的样式表 第三方库真难写CSS 就应该先写后端的 啊啊啊啊啊啊 -->
|
<!-- 妈的黑化了 私人玩意这么难整 早知道 z-index 弄死它得了 浪费我时间 我就没试过这么离谱的样式表 第三方库真难写CSS 就应该先写后端的 啊啊啊啊啊啊 -->
|
||||||
<!-- 不黑化了 因为 stickyfill -->
|
<!-- 不黑化了 因为 stickyfill -->
|
||||||
<div class="mdui-toolbar mdui-theme-color-auto"
|
<div class="mdui-toolbar mdui-theme-color-auto"
|
||||||
style="position: sticky;max-width: 100%;margin-bottom: -30px;bottom: 0;z-index: 101;" n-id="inputToolbar">
|
style="position: sticky;max-width: 100%;margin-top: 1px;bottom: 0;z-index: 101;padding-top: 7px;" n-id="inputToolbar">
|
||||||
<ul class="mdui-menu" id="msg-input-more">
|
<ul class="mdui-menu" id="msg-input-more">
|
||||||
<li class="mdui-menu-item">
|
<li class="mdui-menu-item">
|
||||||
<a class="mdui-ripple">插入图片</a>
|
<a class="mdui-ripple">插入图片</a>
|
||||||
@@ -199,9 +185,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mdui-dialog-actions">
|
<div class="mdui-dialog-actions">
|
||||||
<button class="mdui-btn mdui-ripple"
|
<button class="mdui-btn mdui-ripple"
|
||||||
onclick="User.signUp(viewBinding.dialogSignInName.val(), viewBinding.dialogSignInPasswd.val(), () => mdui.snackbar('注册成功, 请直接点击登录即可~'))">注册</button>
|
onclick="CurrentUser.signUp(viewBinding.dialogSignInName.val(), viewBinding.dialogSignInPasswd.val(), () => mdui.snackbar('注册成功, 请直接点击登录即可~'))">注册</button>
|
||||||
<button class="mdui-btn mdui-ripple" n-id="dialogSignInEnter"
|
<button class="mdui-btn mdui-ripple" n-id="dialogSignInEnter"
|
||||||
onclick="User.signInWithDialog(viewBinding.dialogSignInName.val(), viewBinding.dialogSignInPasswd.val())">登录</button>
|
onclick="CurrentUser.signInWithDialog(viewBinding.dialogSignInName.val(), viewBinding.dialogSignInPasswd.val())">登录</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -236,7 +222,7 @@
|
|||||||
<button class="mdui-btn mdui-ripple" n-id="dialogEditNickClose" mdui-dialog-close
|
<button class="mdui-btn mdui-ripple" n-id="dialogEditNickClose" mdui-dialog-close
|
||||||
onclick="new mdui.Dialog(viewBinding.dialogSettings.get(0)).open()">关闭</button>
|
onclick="new mdui.Dialog(viewBinding.dialogSettings.get(0)).open()">关闭</button>
|
||||||
<button class="mdui-btn mdui-ripple"
|
<button class="mdui-btn mdui-ripple"
|
||||||
onclick="User.setNick(viewBinding.dialogEditNickNick.val(), () => {mdui.snackbar('已保存, 刷新页面生效');viewBinding.dialogEditNickClose.click()})">保存</button>
|
onclick="CurrentUser.setNick(viewBinding.dialogEditNickNick.val(), () => {mdui.snackbar('已保存, 刷新页面生效');viewBinding.dialogEditNickClose.click()})">保存</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -291,7 +277,7 @@
|
|||||||
<i class="mdui-list-item-icon mdui-icon material-icons">edit</i>
|
<i class="mdui-list-item-icon mdui-icon material-icons">edit</i>
|
||||||
<div class="mdui-list-item-content">修改昵称</div>
|
<div class="mdui-list-item-content">修改昵称</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="mdui-list-item mdui-ripple" onclick="User.uploadHeadImage()">
|
<li class="mdui-list-item mdui-ripple" onclick="CurrentUser.uploadHeadImage()">
|
||||||
<i class="mdui-list-item-icon mdui-icon material-icons">account_circle</i>
|
<i class="mdui-list-item-icon mdui-icon material-icons">account_circle</i>
|
||||||
<div class="mdui-list-item-content">上传头像</div>
|
<div class="mdui-list-item-content">上传头像</div>
|
||||||
</li>
|
</li>
|
||||||
@@ -304,7 +290,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mdui-hidden">
|
<div class="mdui-hidden">
|
||||||
<input type="file" n-id="uploadHeadImage" name="选择头像" onchange="User.uploadHeadImageCallback(this)"
|
<input type="file" n-id="uploadHeadImage" name="选择头像" onchange="CurrentUser.uploadHeadImageCallback(this)"
|
||||||
accept="image/png, image/jpeg" />
|
accept="image/png, image/jpeg" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -312,7 +298,12 @@
|
|||||||
<script src="https://unpkg.com/crypto-js@4.2.0/crypto-js.js"></script>
|
<script src="https://unpkg.com/crypto-js@4.2.0/crypto-js.js"></script>
|
||||||
<script src="https://unpkg.com/socket.io-client@4.7.4/dist/socket.io.min.js"></script>
|
<script src="https://unpkg.com/socket.io-client@4.7.4/dist/socket.io.min.js"></script>
|
||||||
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
|
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
|
||||||
<script src="index.js"></script>
|
<!-- 核心脚本部分 -->
|
||||||
|
<script src="utils.js"></script>
|
||||||
|
<script src="manager.js"></script>
|
||||||
|
<script src="ui.js"></script>
|
||||||
|
<script src="handler.js"></script>
|
||||||
|
<script src="finally.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,816 +0,0 @@
|
|||||||
/*
|
|
||||||
* 铃之椅 - 把选择权还给用户, 让聊天权掌握在用户手中
|
|
||||||
* Copyright 2024 满月叶
|
|
||||||
* GitHub: https://github.com/MoonLeeeaf/LingChair-Web-Client
|
|
||||||
* 本项目使用 Apache 2.0 协议开源
|
|
||||||
*
|
|
||||||
* Copyright 2024 MoonLeeeaf
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const sleep = (t) => new Promise((res) => setTimeout(res, t))
|
|
||||||
|
|
||||||
const UrlArgs = new URL(location.href).searchParams
|
|
||||||
|
|
||||||
// https://www.ruanyifeng.com/blog/2021/09/detecting-mobile-browser.html
|
|
||||||
function isMobile() {
|
|
||||||
return ('ontouchstart' in document.documentElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setOnRightClick(e, cb) {
|
|
||||||
if (!(e instanceof jQuery))
|
|
||||||
e = $(e)
|
|
||||||
|
|
||||||
let longPressTimer
|
|
||||||
if (!cb) throw new Error("定义回调!!!!")
|
|
||||||
e.on('contextmenu', function (e) {
|
|
||||||
e.preventDefault() // 阻止默认右键菜单
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
|
|
||||||
e.on('mousedown', function () {
|
|
||||||
longPressTimer = setTimeout(function () {
|
|
||||||
cb()
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
|
|
||||||
e.on('mouseup', function () {
|
|
||||||
clearTimeout(longPressTimer)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UrlArgs.get("debug")) {
|
|
||||||
let script = document.createElement('script')
|
|
||||||
script.src = "//cdn.jsdelivr.net/npm/eruda"
|
|
||||||
document.body.appendChild(script)
|
|
||||||
script.onload = () => eruda.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 经常会因为这个指定ID为位置导致一些莫名BUG
|
|
||||||
if (location.href.includes("#")) location.replace(location.href.substring(0, location.href.indexOf("#")))
|
|
||||||
|
|
||||||
const mdui_snackbar = mdui.snackbar
|
|
||||||
mdui.snackbar = (m) => {
|
|
||||||
let t = m
|
|
||||||
if (m instanceof Object)
|
|
||||||
t = JSON.stringify(m)
|
|
||||||
mdui_snackbar(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkEmpty = (i) => {
|
|
||||||
if (i instanceof Array) {
|
|
||||||
for (let k of i) {
|
|
||||||
if (checkEmpty(k)) return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (i == null) || ("" === i) || (0 === i)
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeHTML(str) {
|
|
||||||
return str.replace(/[<>&"']/g, function (match) {
|
|
||||||
switch (match) {
|
|
||||||
case '<':
|
|
||||||
return '<'
|
|
||||||
case '>':
|
|
||||||
return '>'
|
|
||||||
case '&':
|
|
||||||
return '&'
|
|
||||||
case '"':
|
|
||||||
return '"'
|
|
||||||
case "'":
|
|
||||||
return '''
|
|
||||||
default:
|
|
||||||
return match
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
class NData {
|
|
||||||
static mount(node) {
|
|
||||||
// 便捷获得指定组件
|
|
||||||
let es = node.querySelectorAll("[n-id]")
|
|
||||||
let ls = {}
|
|
||||||
es.forEach((i) => ls[$(i).attr("n-id")] = $(i))
|
|
||||||
|
|
||||||
// input 组件与 localStorage 绑定
|
|
||||||
es = node.querySelectorAll("[n-input-ls]")
|
|
||||||
es.forEach((e) => {
|
|
||||||
let j = $(e)
|
|
||||||
j.val(localStorage.getItem(j.attr("n-input-ls")))
|
|
||||||
j.blur(() => localStorage.setItem(j.attr("n-input-ls"), j.val()))
|
|
||||||
})
|
|
||||||
return ls
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 快捷获取指定视图
|
|
||||||
let viewBinding = NData.mount($("#app").get(0))
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: "res/config.json",
|
|
||||||
dataType: "json",
|
|
||||||
success: (c) => {
|
|
||||||
viewBinding.appTitle.text(c.appTitle)
|
|
||||||
if (!c.canChangeServer) {
|
|
||||||
viewBinding.dialogSignInServerLabel.hide()
|
|
||||||
viewBinding.drawerChangeServer.hide()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
/* // Toolbar 快捷按钮绑定
|
|
||||||
viewBinding.contactsRefresh.hide()
|
|
||||||
viewBinding.contactsAdd.hide()
|
|
||||||
viewBinding.tabChatList.on("show.mdui.tab", () => {
|
|
||||||
viewBinding.contactsRefresh.hide()
|
|
||||||
viewBinding.contactsAdd.hide()
|
|
||||||
})
|
|
||||||
viewBinding.tabContacts.on("show.mdui.tab", () => {
|
|
||||||
viewBinding.contactsRefresh.show()
|
|
||||||
viewBinding.contactsAdd.show()
|
|
||||||
})
|
|
||||||
viewBinding.tabChatSeesion.on("show.mdui.tab", () => {
|
|
||||||
viewBinding.contactsRefresh.hide()
|
|
||||||
viewBinding.contactsAdd.hide()
|
|
||||||
}) */
|
|
||||||
|
|
||||||
/* viewBinding.tabChatSeesion.hide() */
|
|
||||||
|
|
||||||
// 关于页面
|
|
||||||
viewBinding.menuAbout.click(() => mdui.alert('这是一个开源项目<br/>作者: MoonLeeeaf<br/>欢迎访问我们的<a class="mdui-text-color-theme-accent" href="https://github.com/LingChair/LingChair">项目主页</a>', '关于 铃之椅', () => { }, { confirmText: "关闭" }))
|
|
||||||
|
|
||||||
viewBinding.drawerChangeServer.click(() => {
|
|
||||||
mdui.prompt('输入服务器地址...(为空则使用当前页面地址)', (value) => {
|
|
||||||
localStorage.server = value
|
|
||||||
mdui.snackbar("更新成功, 刷新页面生效")
|
|
||||||
}, () => { }, {
|
|
||||||
confirmText: "确定",
|
|
||||||
cancelText: "取消"
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
viewBinding.drawerSignOut.click(() => {
|
|
||||||
mdui.confirm('确定要登出账号吗', () => {
|
|
||||||
User.signOutAndReload()
|
|
||||||
}, () => { }, {
|
|
||||||
confirmText: "确定",
|
|
||||||
cancelText: "取消"
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
viewBinding.sendMsg.click((a) => {
|
|
||||||
let text = viewBinding.inputMsg.val()
|
|
||||||
if (text.trim() !== "")
|
|
||||||
ChatMsgAdapter.send(text)
|
|
||||||
})
|
|
||||||
|
|
||||||
viewBinding.inputMsg.keydown((e) => {
|
|
||||||
if (e.ctrlKey && e.keyCode === 13)
|
|
||||||
viewBinding.sendMsg.click()
|
|
||||||
})
|
|
||||||
|
|
||||||
viewBinding.dialogSignInPasswd.keydown((e) => {
|
|
||||||
if (e.keyCode === 13)
|
|
||||||
viewBinding.dialogSignInEnter.click()
|
|
||||||
})
|
|
||||||
|
|
||||||
viewBinding.switchNotifications.click((a) => {
|
|
||||||
if ((localStorage.useNotifications == "true" || localStorage.useNotifications != null) && localStorage.useNotifications != "false") {
|
|
||||||
localStorage.useNotifications = "false"
|
|
||||||
viewBinding.switchNotificationsIcon.text("notifications_off")
|
|
||||||
} else {
|
|
||||||
localStorage.useNotifications = "true"
|
|
||||||
viewBinding.switchNotificationsIcon.text("notifications")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (localStorage.useNotifications == "true")
|
|
||||||
viewBinding.switchNotificationsIcon.text("notifications")
|
|
||||||
|
|
||||||
// https://www.runoob.com/w3cnote/javascript-copy-clipboard.html
|
|
||||||
function copyText(t) {
|
|
||||||
let btn = viewBinding.textCopierBtn
|
|
||||||
btn.attr("data-clipboard-text", t)
|
|
||||||
new ClipboardJS(btn.get(0)).on('success', (e) => {
|
|
||||||
e.clearSelection()
|
|
||||||
})
|
|
||||||
btn.click()
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://zhuanlan.zhihu.com/p/162910462
|
|
||||||
Date.prototype.format = function (tms, format) {
|
|
||||||
let tmd = new Date(tms)
|
|
||||||
/*
|
|
||||||
* 例子: format="YYYY-MM-dd hh:mm:ss";
|
|
||||||
*/
|
|
||||||
var o = {
|
|
||||||
"M+": tmd.getMonth() + 1, // month
|
|
||||||
"d+": tmd.getDate(), // day
|
|
||||||
"h+": tmd.getHours(), // hour
|
|
||||||
"m+": tmd.getMinutes(), // minute
|
|
||||||
"s+": tmd.getSeconds(), // second
|
|
||||||
"q+": Math.floor((tmd.getMonth() + 3) / 3), // quarter
|
|
||||||
"S": tmd.getMilliseconds()
|
|
||||||
// millisecond
|
|
||||||
}
|
|
||||||
if (/(y+)/.test(format)) {
|
|
||||||
format = format.replace(RegExp.$1, (tmd.getFullYear() + "")
|
|
||||||
.substr(4 - RegExp.$1.length));
|
|
||||||
}
|
|
||||||
for (var k in o) {
|
|
||||||
if (new RegExp("(" + k + ")").test(format)) {
|
|
||||||
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
|
|
||||||
: ("00" + o[k]).substr(("" + o[k]).length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
// new mdui.Drawer('#main-drawer').close()
|
|
||||||
|
|
||||||
class NickCache {
|
|
||||||
static data = {}
|
|
||||||
static async getNick(name) {
|
|
||||||
return await new Promise((res, rej) => {
|
|
||||||
// 这个this别摆着不放啊 不然两下就会去世
|
|
||||||
let nick = this.data[name]
|
|
||||||
if (nick == null)
|
|
||||||
client.emit("user.getNick", { name: localStorage.userName }, (re) => {
|
|
||||||
let nk = re.data != null ? re.data.nick : name
|
|
||||||
if (nk == null) nk = name
|
|
||||||
this.data[name] = nk
|
|
||||||
res(nk)
|
|
||||||
})
|
|
||||||
else
|
|
||||||
res(nick)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 既然已经有 Notification 了, 那用回中文也不过分吧 :)
|
|
||||||
class 通知 {
|
|
||||||
constructor() {
|
|
||||||
this.args = {}
|
|
||||||
this.title = ""
|
|
||||||
}
|
|
||||||
static checkAvailable() {
|
|
||||||
return ("Notification" in window)
|
|
||||||
}
|
|
||||||
static async request() {
|
|
||||||
if (!this.checkAvailable()) return false
|
|
||||||
return (await Notification.requestPermission())
|
|
||||||
}
|
|
||||||
setId(id) {
|
|
||||||
this.args.tag = id
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
setTitle(t) {
|
|
||||||
this.title = t
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
setMessage(m) {
|
|
||||||
this.args.body = m
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
setIcon(i) {
|
|
||||||
this.args.icon = i
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
setImage(i) {
|
|
||||||
this.args.image = i
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
setData(data) {
|
|
||||||
this.args.data = data
|
|
||||||
}
|
|
||||||
show(onclick/*, onclose*/) {
|
|
||||||
if (!通知.checkAvailable()) return
|
|
||||||
if (localStorage.useNotifications !== "true") return
|
|
||||||
let n = new Notification(this.title, this.args)
|
|
||||||
n.onclick = onclick == null ? () => n.close() : (n) => onclick(n)
|
|
||||||
// n.onclose = onclose
|
|
||||||
// n.close()
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ContactsList {
|
|
||||||
static async reloadList() {
|
|
||||||
client.emit("user.getFriends", {
|
|
||||||
name: localStorage.userName,
|
|
||||||
accessToken: await User.getAccessToken(),
|
|
||||||
}, async (re) => {
|
|
||||||
if (re.code !== 0)
|
|
||||||
return mdui.snackbar(re.msg)
|
|
||||||
|
|
||||||
viewBinding.contactsList.empty()
|
|
||||||
let ls = re.data.friends
|
|
||||||
for (let index in ls) {
|
|
||||||
let name = ls[index]
|
|
||||||
let dick = await NickCache.getNick(name)
|
|
||||||
/*client.emit("user.getNick", { name: localStorage.userName }, (re) => {
|
|
||||||
let nick = re.data == null ? re.data.nick : null
|
|
||||||
let name = ls[index]*/
|
|
||||||
$($.parseHTML(`<li class="mdui-list-item mdui-ripple" mdui-drawer-close><div class="mdui-list-item-avatar"><img src="` + User.getUserHeadUrl(name) + `" onerror="this.src='res/default_head.png'" /></div><div class="mdui-list-item-content">` + dick + `</div></li>`)).appendTo(viewBinding.contactsList).click(() => {
|
|
||||||
ChatMsgAdapter.switchTo(name, "single")
|
|
||||||
})
|
|
||||||
//})
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// 添加联系人,好友或者群聊
|
|
||||||
static add(name, type) {
|
|
||||||
if (type == "single") {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static openAddDialog() {
|
|
||||||
new mdui.Dialog(viewBinding.dialogNewContact.get(0)).open()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 第一次写前端的消息加载, 代码很乱, 还请原谅~
|
|
||||||
|
|
||||||
// v0.7.0 大改UI 畏惧了 太庞大了
|
|
||||||
|
|
||||||
class ChatPage {
|
|
||||||
static cached = {}
|
|
||||||
constructor(name, type) {
|
|
||||||
|
|
||||||
}
|
|
||||||
static switchTo(name, type) {
|
|
||||||
if (!this.cached[name])
|
|
||||||
this.cached[name] = new ChatPage(name, type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChatMsgAdapter {
|
|
||||||
static type
|
|
||||||
static target
|
|
||||||
// static msgList
|
|
||||||
static minMsgId
|
|
||||||
static time
|
|
||||||
static bbn
|
|
||||||
static resizeDick
|
|
||||||
// 切换聊天对象
|
|
||||||
static async switchTo(name, type) {
|
|
||||||
viewBinding.tabChatSeesion.show()
|
|
||||||
viewBinding.tabChatSeesion.text(await NickCache.getNick(name))
|
|
||||||
viewBinding.tabChatSeesion.get(0).click()
|
|
||||||
|
|
||||||
this.type = type
|
|
||||||
this.target = name
|
|
||||||
// this.msgList = []
|
|
||||||
this.minMsgId = null
|
|
||||||
|
|
||||||
viewBinding.pageChatSeesion.empty()
|
|
||||||
|
|
||||||
await this.loadMore()
|
|
||||||
this.scrollToBottom()
|
|
||||||
}
|
|
||||||
// 发送消息
|
|
||||||
static async send(msg) {
|
|
||||||
client.emit("user.sendSingleMsg", {
|
|
||||||
name: localStorage.userName,
|
|
||||||
target: this.target,
|
|
||||||
msg: msg,
|
|
||||||
accessToken: await User.getAccessToken(),
|
|
||||||
}, async (re) => {
|
|
||||||
if (re.code !== 0)
|
|
||||||
return mdui.snackbar(re.msg)
|
|
||||||
|
|
||||||
viewBinding.inputMsg.val("")
|
|
||||||
|
|
||||||
// 微机课闲的没事干玩玩 发现私聊会多发一个(一个是本地的, 另一个是发送成功的) 选择一个关掉就好了
|
|
||||||
// 这里我选择服务端不发送回调, 不然多设备同步会吵死
|
|
||||||
// 错了 应该是客户端少发条才对 不然不能多设备同步
|
|
||||||
if ((ChatMsgAdapter.target !== localStorage.userName) && ChatMsgAdapter.type === "single") {
|
|
||||||
let i = ChatMsgAdapter.isAtBottom()
|
|
||||||
await ChatMsgAdapter.addMsg(localStorage.userName, msg, re.data.time, re.data.msgid)
|
|
||||||
if (i) ChatMsgAdapter.scrollToBottom()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
static async getHistroy(start, limit) {
|
|
||||||
return new Promise(async (res, rej) => {
|
|
||||||
client.emit("user.getSingleChatHistroy", {
|
|
||||||
name: localStorage.userName,
|
|
||||||
target: this.target,
|
|
||||||
limit: limit,
|
|
||||||
accessToken: await User.getAccessToken(),
|
|
||||||
startId: start,
|
|
||||||
}, (re) => {
|
|
||||||
if (re.code !== 0)
|
|
||||||
return mdui.snackbar(re.msg)
|
|
||||||
res(re.data.histroy)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
static async loadMore(limit) {
|
|
||||||
let histroy = await this.getHistroy(this.minMsgId, limit == null ? 13 : limit)
|
|
||||||
|
|
||||||
if (histroy.length == 0)
|
|
||||||
return mdui.snackbar("已经加载完了~")
|
|
||||||
|
|
||||||
let re = this.minMsgId != null
|
|
||||||
this.minMsgId = histroy[0].msgid - 1
|
|
||||||
let sc = 0
|
|
||||||
if (re) histroy = histroy.reverse()
|
|
||||||
for (let index in histroy) {
|
|
||||||
let i = histroy[index]
|
|
||||||
let e = await this.addMsg(i.name, i.msg, i.time, re, i.msgid)
|
|
||||||
// 因为某些因素直接DEBUG到吐血 断点继续都不报错 原因不明
|
|
||||||
sc = sc + (e == null ? 25 : e.get(0).offsetTop)
|
|
||||||
}
|
|
||||||
window.scrollBy({
|
|
||||||
top: sc,
|
|
||||||
behavior: 'smooth'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
static addSystemMsg(m, re) {
|
|
||||||
let e
|
|
||||||
if (re)
|
|
||||||
// 加到头部
|
|
||||||
e = $($.parseHTML(m)).prependTo(viewBinding.pageChatSeesion)
|
|
||||||
else
|
|
||||||
// 加到尾部
|
|
||||||
e = $($.parseHTML(m)).appendTo(viewBinding.pageChatSeesion)
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
static isAtBottom() {
|
|
||||||
let elementRect = viewBinding.pageChatSeesion.get(0).getBoundingClientRect()
|
|
||||||
return (elementRect.bottom <= window.innerHeight)
|
|
||||||
}
|
|
||||||
// 添加消息 返回消息的JQ对象
|
|
||||||
// name: 用户id m: 消息 t: 时间戳 re: 默认加到尾部 msgid: 消息id
|
|
||||||
static async addMsg(name, m, t, re, msgid) {
|
|
||||||
|
|
||||||
let nick = await NickCache.getNick(name) // re.data == null ? name : re.data.nick
|
|
||||||
|
|
||||||
let msg = escapeHTML(m)
|
|
||||||
|
|
||||||
let temp
|
|
||||||
if (name === localStorage.userName)
|
|
||||||
temp = `<div class="chat-message-right">
|
|
||||||
<div class="message-content-with-nickname-right">
|
|
||||||
<span class="nickname">` + nick + `</span>
|
|
||||||
<div class="message-content mdui-card" id="msgid_` + msgid + `">
|
|
||||||
<span id="msg-content">` + msg + `</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<img class="avatar" src="` + User.getUserHeadUrl(name) + `" onerror="this.src='res/default_head.png'" />
|
|
||||||
</div>`
|
|
||||||
else
|
|
||||||
temp = `<div class="chat-message-left">
|
|
||||||
<img class="avatar" src="` + User.getUserHeadUrl(name) + `" onerror="this.src='res/default_head.png'" />
|
|
||||||
<div class="message-content-with-nickname-left">
|
|
||||||
<span class="nickname">` + nick + `</span>
|
|
||||||
<div class="message-content mdui-card" id="msgid_` + msgid + `">
|
|
||||||
<span id="msg-content">` + msg + `</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`
|
|
||||||
|
|
||||||
let bn = new Date(t).getMinutes()
|
|
||||||
let e
|
|
||||||
if (re) {
|
|
||||||
this.addSystemMsg(temp, re)
|
|
||||||
if (this.bbn != bn) {
|
|
||||||
e = this.addSystemMsg(`<div class="mdui-center">` + new Date().format(t == null ? Date.parse("1000-1-1 00:00:00") : t, "yyyy年MM月dd日 hh:mm:ss") + `</div>`, re)
|
|
||||||
this.time = bn
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.bbn != bn) {
|
|
||||||
e = this.addSystemMsg(`<div class="mdui-center">` + new Date().format(t == null ? Date.parse("1000-1-1 00:00:00") : t, "yyyy年MM月dd日 hh:mm:ss") + `</div>`, re)
|
|
||||||
this.time = bn
|
|
||||||
}
|
|
||||||
this.addSystemMsg(temp, re)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bbn = new Date(t).getMinutes()
|
|
||||||
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
// 添加消息记录 作用在 UI 和 msgList
|
|
||||||
/* static async addMsgLocal(name, m, t, msgid) {
|
|
||||||
this.msgList.push({
|
|
||||||
name: name,
|
|
||||||
msg: m,
|
|
||||||
msgid: msgid,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.addMsg(name, m, t)
|
|
||||||
} */
|
|
||||||
// 从服务器加载一些聊天记录, limit默认=13
|
|
||||||
static async loadMsgs(limit) {
|
|
||||||
let histroy = await this.getHistroy(this.msgList[0] == null ? null : this.msgList[0].msgid - 1, limit == null ? 13 : limit)
|
|
||||||
this.msgList = histroy
|
|
||||||
}
|
|
||||||
/* static async loadMsgsFromList(lst) {
|
|
||||||
for (let index in lst) {
|
|
||||||
let i = lst[index]
|
|
||||||
await this.addMsg(i.name, i.msg, i.time)
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
static scrollToBottom() {
|
|
||||||
// 吐了啊 原来这样就行了 我何必在子element去整啊
|
|
||||||
viewBinding.chatPager.get(0).scrollBy({
|
|
||||||
top: 1145141919810,
|
|
||||||
behavior: 'smooth'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// 从本地加载
|
|
||||||
/*static loadMsgsFromLocal(target) {
|
|
||||||
let data = localStorage["chat_msg_" + target]
|
|
||||||
if (data == null || data === "[]")
|
|
||||||
return []
|
|
||||||
|
|
||||||
return JSON.parse(data)
|
|
||||||
}
|
|
||||||
// 把当前聊天记录储存到本地
|
|
||||||
static saveToLocal() {
|
|
||||||
localStorage["chat_msg_" + this.target] = JSON.stringify(this.msgList)
|
|
||||||
}*/
|
|
||||||
// 自动调整使输入框置底 CSS真tm靠不住啊
|
|
||||||
static initInputResizer() {
|
|
||||||
// 实验表面移动端切出输入法时会触发1-2次resize事件
|
|
||||||
// 可以利用这个特性来实现自动滚动文本
|
|
||||||
let resize = () => {
|
|
||||||
viewBinding.pageChatSeesion.height(window.innerHeight - viewBinding.inputToolbar.height() - $("header.mdui-appbar").height() - viewBinding.chatTab.height() - 50)
|
|
||||||
let ledi = this.resizeDick - window.innerHeight
|
|
||||||
if (isMobile()) viewBinding.chatPager.get(0).scrollBy({
|
|
||||||
// 5.19晚10:56分调配出来的秘方
|
|
||||||
// < 0 为窗口变大
|
|
||||||
// cnm的,调试十万次就你tm检测不到底是吧,就你语法天天错误是吧
|
|
||||||
// 欺负我现在用不了电脑
|
|
||||||
top: -(ledi) * ((ledi < 0 && this.isAtBottom()) ? 6 : -1), // (ledi < 0 ? 6 : 6),
|
|
||||||
behavior: 'smooth'
|
|
||||||
})
|
|
||||||
this.resizeDick = window.innerHeight
|
|
||||||
}
|
|
||||||
window.addEventListener("resize", resize)
|
|
||||||
resize()
|
|
||||||
}
|
|
||||||
// 为消息设置长按/右键事件
|
|
||||||
static initMsgElementEvents() {
|
|
||||||
let listeners = {}
|
|
||||||
let menu
|
|
||||||
let callback = (e) => {
|
|
||||||
if (menu) menu.close()
|
|
||||||
// 从 span 切到 div
|
|
||||||
if (e.get(0).tagName.toLowerCase() != "div") e = $(e.get(0).parentNode)
|
|
||||||
// 从 消息框 切到 更上层
|
|
||||||
e = $(e.get(0).parentNode)
|
|
||||||
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>
|
|
||||||
</li>
|
|
||||||
<li class="mdui-menu-item">
|
|
||||||
<a onclick="mdui.alert('未制作功能', '提示', () => { }, { confirmText: '关闭' })" class="mdui-ripple">转发</a>
|
|
||||||
</li>
|
|
||||||
</ul>`)
|
|
||||||
let $menu = $(menuHtml)
|
|
||||||
e.before($menu)
|
|
||||||
menu = new mdui.Menu(e.get(0), menuHtml, {
|
|
||||||
position: "bottom",
|
|
||||||
align: "right",
|
|
||||||
// covered: true,
|
|
||||||
})
|
|
||||||
$menu.on('closed.mdui.menu', () => {
|
|
||||||
$(menuHtml).remove()
|
|
||||||
})
|
|
||||||
menu.open()
|
|
||||||
}
|
|
||||||
viewBinding.pageChatSeesion.on('contextmenu mousedown mouseup', '.message-content', (e) => {
|
|
||||||
let eventType = e.type
|
|
||||||
let self = $(e.target)
|
|
||||||
|
|
||||||
// 根据事件类型执行不同操作
|
|
||||||
switch (eventType) {
|
|
||||||
case 'contextmenu':
|
|
||||||
e.preventDefault() // 阻止默认行为
|
|
||||||
callback(self)
|
|
||||||
break
|
|
||||||
case 'mousedown':
|
|
||||||
if (!isMobile()) return
|
|
||||||
listeners[self + ""] = setTimeout(() => {
|
|
||||||
callback(self)
|
|
||||||
}, 300) // 300颗够吗 应该够吧
|
|
||||||
break
|
|
||||||
case 'mouseup':
|
|
||||||
if (!isMobile()) return
|
|
||||||
clearTimeout(listeners[self + ""])
|
|
||||||
listeners[self + ""] = null
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Hash {
|
|
||||||
static md5(data) {
|
|
||||||
return CryptoJS.MD5(data).toString(CryptoJS.enc.Base64)
|
|
||||||
}
|
|
||||||
static sha256(data) {
|
|
||||||
return CryptoJS.SHA256(data).toString(CryptoJS.enc.Base64)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class User {
|
|
||||||
static myAccessToken
|
|
||||||
// 登录账号 通过回调函数返回刷新令牌
|
|
||||||
static signIn(name, passwd, cb) {
|
|
||||||
client.emit("user.signIn", {
|
|
||||||
name: name,
|
|
||||||
passwd: Hash.sha256(passwd) + Hash.md5(passwd),
|
|
||||||
}, (re) => {
|
|
||||||
if (re.code !== 0)
|
|
||||||
return mdui.snackbar(re.msg)
|
|
||||||
|
|
||||||
cb(re)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
static signUp(name, passwd, cb) {
|
|
||||||
client.emit("user.signUp", {
|
|
||||||
name: name,
|
|
||||||
passwd: Hash.sha256(passwd) + Hash.md5(passwd),
|
|
||||||
}, (re) => {
|
|
||||||
if (re.code !== 0)
|
|
||||||
return mdui.snackbar(re.msg)
|
|
||||||
|
|
||||||
cb(re)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// 为登录对话框编写的
|
|
||||||
static signInWithDialog(name, passwd) {
|
|
||||||
this.signIn(name, passwd, (re) => {
|
|
||||||
localStorage.refreshToken = re.data.refreshToken
|
|
||||||
localStorage.isSignIn = true
|
|
||||||
|
|
||||||
location.reload()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
static async setNick(nick, cb) {
|
|
||||||
client.emit("user.setNick", {
|
|
||||||
name: localStorage.userName,
|
|
||||||
accessToken: await this.getAccessToken(),
|
|
||||||
nick: nick,
|
|
||||||
}, (re) => {
|
|
||||||
if (re.code !== 0)
|
|
||||||
return mdui.snackbar(re.msg)
|
|
||||||
if (cb) cb()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// 获取头像链接
|
|
||||||
static getUserHeadUrl(name) {
|
|
||||||
return client.io.uri + "/users_head/" + name + ".png"
|
|
||||||
}
|
|
||||||
static async getAccessToken(er) {
|
|
||||||
if (this.myAccessToken == null)
|
|
||||||
this.myAccessToken = await new Promise((res) => {
|
|
||||||
client.emit("user.getAccessToken", { name: localStorage.userName, refreshToken: localStorage.refreshToken }, (r) => {
|
|
||||||
if (r.data != null) res(r.data.accessToken)
|
|
||||||
if (er != null) er(r.msg)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
return this.myAccessToken
|
|
||||||
}
|
|
||||||
static uploadHeadImage() {
|
|
||||||
viewBinding.uploadHeadImage.click()
|
|
||||||
}
|
|
||||||
static async uploadHeadImageCallback(self) {
|
|
||||||
let img = self.files[0]
|
|
||||||
client.emit("user.setHeadImage", {
|
|
||||||
name: localStorage.userName,
|
|
||||||
accessToken: await User.getAccessToken(),
|
|
||||||
headImage: img,
|
|
||||||
}, (re) => mdui.snackbar(re.msg))
|
|
||||||
}
|
|
||||||
static auth() {
|
|
||||||
client.emit("user.auth", { name: localStorage.userName, refreshToken: localStorage.refreshToken }, (re) => {
|
|
||||||
if (re.code !== 0) {
|
|
||||||
console.error(re)
|
|
||||||
if (!re.invalid)
|
|
||||||
return mdui.snackbar("验证用户失败!")
|
|
||||||
|
|
||||||
mdui.alert("账号刷新令牌已过期, 请重新登录哦", "提示", () => User.signOutAndReload(), {
|
|
||||||
confirmText: "确定",
|
|
||||||
closeOnConfirm: false,
|
|
||||||
closeOnEsc: false,
|
|
||||||
modal: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
static signOutAndReload() {
|
|
||||||
localStorage.refreshToken = ""
|
|
||||||
localStorage.isSignIn = false
|
|
||||||
|
|
||||||
setTimeout(() => location.reload(), 300)
|
|
||||||
}
|
|
||||||
static registerCallback() {
|
|
||||||
client.on("msg.receive", async (a) => {
|
|
||||||
if (checkEmpty([a.target, a.msg, a.type]))
|
|
||||||
return
|
|
||||||
|
|
||||||
if ((ChatMsgAdapter.target === a.target) && (ChatMsgAdapter.type === a.type)) {
|
|
||||||
let i = ChatMsgAdapter.isAtBottom()
|
|
||||||
await ChatMsgAdapter.addMsg(a.target, a.msg.msg, a.msg.time)
|
|
||||||
if (i) ChatMsgAdapter.scrollToBottom()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ChatMsgAdapter.target !== localStorage.userName) {
|
|
||||||
let n = new 通知().setTitle("" + await NickCache.getNick(a.target)).setMessage(a.msg.msg).setIcon(User.getUserHeadUrl(a.target)).show(async () => {
|
|
||||||
await ChatMsgAdapter.switchTo(a.target, a.type)
|
|
||||||
location.replace("#msgid_" + a.msg.msgid)
|
|
||||||
n.close()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
static async openProfileDialog(name) {
|
|
||||||
viewBinding.dialogProfileHead.attr("src", User.getUserHeadUrl(name))
|
|
||||||
viewBinding.dialogProfileNick.text(await NickCache.getNick(name))
|
|
||||||
new mdui.Dialog(viewBinding.dialogProfile).open()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 没有刷新令牌需要重新登录 或者初始化
|
|
||||||
if (!localStorage.refreshToken || localStorage.refreshToken === "")
|
|
||||||
localStorage.isSignIn = false
|
|
||||||
|
|
||||||
let client
|
|
||||||
function setUpClient(server) {
|
|
||||||
if (server && server !== "")
|
|
||||||
client = new io(server, {
|
|
||||||
auth: {
|
|
||||||
name: localStorage.isSignIn === "false" ? null : localStorage.userName
|
|
||||||
}
|
|
||||||
})
|
|
||||||
else
|
|
||||||
client = new io({
|
|
||||||
auth: {
|
|
||||||
name: localStorage.isSignIn === "false" ? null : localStorage.userName
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
client.on("connect", () => {
|
|
||||||
User.auth()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (!localStorage.server || localStorage.server === "")
|
|
||||||
setUpClient()
|
|
||||||
else
|
|
||||||
setUpClient(localStorage.server)
|
|
||||||
|
|
||||||
// 登录到账号
|
|
||||||
let dialogSignIn
|
|
||||||
// 谨防 localStorage 字符串数据大坑
|
|
||||||
if (localStorage.isSignIn == "false")
|
|
||||||
dialogSignIn = new mdui.Dialog(viewBinding.dialogSignIn.get(0), {
|
|
||||||
modal: true,
|
|
||||||
closeOnEsc: false,
|
|
||||||
history: false,
|
|
||||||
}).open()
|
|
||||||
else {
|
|
||||||
(async () => viewBinding.userNick.text(await NickCache.getNick(localStorage.userName)))()
|
|
||||||
let hello
|
|
||||||
let nowHour = new Date().getHours()
|
|
||||||
if (nowHour >= 6 && nowHour <= 11) hello = "早安"
|
|
||||||
else if (nowHour == 12) hello = "中午好"
|
|
||||||
else if (nowHour >= 13 && nowHour <= 18) hello = "下午好"
|
|
||||||
else if (nowHour >= 19 && nowHour < 22) hello = "晚上好"
|
|
||||||
else hello = "晚安"
|
|
||||||
viewBinding.helloText.text(hello)
|
|
||||||
|
|
||||||
viewBinding.userHead.attr("src", User.getUserHeadUrl(localStorage.userName))
|
|
||||||
|
|
||||||
ContactsList.reloadList()
|
|
||||||
|
|
||||||
User.registerCallback()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 感谢AI的力量
|
|
||||||
Stickyfill.add($("*").filter((a, b) => $(b).css('position') === 'sticky'))
|
|
||||||
|
|
||||||
ChatMsgAdapter.initMsgElementEvents()
|
|
||||||
|
|
||||||
ChatMsgAdapter.initInputResizer()
|
|
||||||
|
|
||||||
function refreshAll() {
|
|
||||||
ContactsList.reloadList()
|
|
||||||
delete NickCache.data
|
|
||||||
NickCache.data = {}
|
|
||||||
}
|
|
||||||
36
ling_chair_http/manager.js
Normal file
36
ling_chair_http/manager.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* ©2024 满月叶
|
||||||
|
* Github: MoonLeeeaf
|
||||||
|
* 资源类
|
||||||
|
*/
|
||||||
|
|
||||||
|
const viewBinding = NData.mount($("#app").get(0))
|
||||||
|
|
||||||
|
let client
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化客户端
|
||||||
|
* @param {String} 服务器地址
|
||||||
|
*/
|
||||||
|
function setUpClient(server) {
|
||||||
|
if (server && server !== "")
|
||||||
|
client = new io(server, {
|
||||||
|
auth: {
|
||||||
|
name: localStorage.isSignIn === "false" ? null : localStorage.userName
|
||||||
|
}
|
||||||
|
})
|
||||||
|
else
|
||||||
|
client = new io({
|
||||||
|
auth: {
|
||||||
|
name: localStorage.isSignIn === "false" ? null : localStorage.userName
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on("connect", () => {
|
||||||
|
User.auth()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
window.viewBinding = viewBinding
|
||||||
|
window.setUpClient = setUpClient
|
||||||
|
window.client = client
|
||||||
@@ -6,9 +6,12 @@
|
|||||||
|
|
||||||
/* 美化UI */
|
/* 美化UI */
|
||||||
|
|
||||||
|
/* 恢复系统字体 */
|
||||||
body {
|
body {
|
||||||
font-family: -apple-system, system-ui, -webkit-system-font;
|
font-family: -apple-system, system-ui, -webkit-system-font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 圆角化 */
|
||||||
.mdui-dialog {
|
.mdui-dialog {
|
||||||
border-radius: 23px;
|
border-radius: 23px;
|
||||||
}
|
}
|
||||||
@@ -42,10 +45,14 @@ body {
|
|||||||
|
|
||||||
/* 配色方案 */
|
/* 配色方案 */
|
||||||
|
|
||||||
.mdui-theme-color-auto {
|
.mdui-list-item-avatar {
|
||||||
background-color: #fff;
|
background-color: rgba(0, 0, 0, 0) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 背景底色 */
|
||||||
|
.mdui-theme-color-auto {
|
||||||
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
}
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
.mdui-theme-color-auto {
|
.mdui-theme-color-auto {
|
||||||
background-color: #303030;
|
background-color: #303030;
|
||||||
|
|||||||
71
ling_chair_http/ui.js
Normal file
71
ling_chair_http/ui.js
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* ©2024 满月叶
|
||||||
|
* Github: MoonLeeeaf
|
||||||
|
* 界面逻辑
|
||||||
|
*/
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "res/config.json",
|
||||||
|
dataType: "json",
|
||||||
|
success: (c) => {
|
||||||
|
viewBinding.appTitle.text(c.appTitle)
|
||||||
|
if (!c.canChangeServer) {
|
||||||
|
viewBinding.dialogSignInServerLabel.hide()
|
||||||
|
viewBinding.drawerChangeServer.hide()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// 关于页面
|
||||||
|
viewBinding.menuAbout.click(() => mdui.alert('这是一个开源项目<br/>作者: MoonLeeeaf<br/>欢迎访问我们的<a class="mdui-text-color-theme-accent" href="https://github.com/LingChair/LingChair">项目主页</a>', '关于 铃之椅', () => { }, { confirmText: "关闭" }))
|
||||||
|
|
||||||
|
viewBinding.drawerChangeServer.click(() => {
|
||||||
|
mdui.prompt('输入服务器地址...(为空则使用当前页面地址)', (value) => {
|
||||||
|
localStorage.server = value
|
||||||
|
mdui.snackbar("更新成功, 刷新页面生效")
|
||||||
|
}, () => { }, {
|
||||||
|
confirmText: "确定",
|
||||||
|
cancelText: "取消"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
viewBinding.drawerSignOut.click(() => {
|
||||||
|
mdui.confirm('确定要登出账号吗', () => {
|
||||||
|
User.signOutAndReload()
|
||||||
|
}, () => { }, {
|
||||||
|
confirmText: "确定",
|
||||||
|
cancelText: "取消"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
viewBinding.sendMsg.click((a) => {
|
||||||
|
let text = viewBinding.inputMsg.val()
|
||||||
|
if (text.trim() !== "")
|
||||||
|
ChatMsgAdapter.send(text)
|
||||||
|
})
|
||||||
|
|
||||||
|
viewBinding.inputMsg.keydown((e) => {
|
||||||
|
if (e.ctrlKey && e.keyCode === 13)
|
||||||
|
viewBinding.sendMsg.click()
|
||||||
|
})
|
||||||
|
|
||||||
|
viewBinding.dialogSignInPasswd.keydown((e) => {
|
||||||
|
if (e.keyCode === 13)
|
||||||
|
viewBinding.dialogSignInEnter.click()
|
||||||
|
})
|
||||||
|
|
||||||
|
viewBinding.switchNotifications.click((a) => {
|
||||||
|
if ((localStorage.useNotifications == "true" || localStorage.useNotifications != null) && localStorage.useNotifications != "false") {
|
||||||
|
localStorage.useNotifications = "false"
|
||||||
|
viewBinding.switchNotificationsIcon.text("notifications_off")
|
||||||
|
} else {
|
||||||
|
localStorage.useNotifications = "true"
|
||||||
|
viewBinding.switchNotificationsIcon.text("notifications")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (localStorage.useNotifications == "true")
|
||||||
|
viewBinding.switchNotificationsIcon.text("notifications")
|
||||||
|
|
||||||
|
viewBinding.inputMsg.blur(() => {
|
||||||
|
window.initInputResizerResize()
|
||||||
|
})
|
||||||
208
ling_chair_http/utils.js
Normal file
208
ling_chair_http/utils.js
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
/*
|
||||||
|
* ©2024 满月叶
|
||||||
|
* Github: MoonLeeeaf
|
||||||
|
* 辅助添加
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 2024.5.28 睡着了
|
||||||
|
const sleep = (t) => new Promise((res) => setTimeout(res, t))
|
||||||
|
|
||||||
|
const UrlArgs = new URL(location.href).searchParams
|
||||||
|
|
||||||
|
// https://www.ruanyifeng.com/blog/2021/09/detecting-mobile-browser.html
|
||||||
|
function isMobile() {
|
||||||
|
return ('ontouchstart' in document.documentElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UrlArgs.get("debug")) {
|
||||||
|
let script = document.createElement('script')
|
||||||
|
script.src = "//cdn.jsdelivr.net/npm/eruda"
|
||||||
|
document.body.appendChild(script)
|
||||||
|
script.onload = () => eruda.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 经常会因为这个指定ID为位置导致一些莫名BUG
|
||||||
|
if (location.href.includes("#")) location.replace(location.href.substring(0, location.href.indexOf("#")))
|
||||||
|
|
||||||
|
const mdui_snackbar = mdui.snackbar
|
||||||
|
mdui.snackbar = (m) => {
|
||||||
|
let t = m
|
||||||
|
if (m instanceof Object)
|
||||||
|
t = JSON.stringify(m)
|
||||||
|
mdui_snackbar(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkEmpty = (i) => {
|
||||||
|
if (i instanceof Array) {
|
||||||
|
for (let k of i) {
|
||||||
|
if (checkEmpty(k)) return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (i == null) || ("" === i) || (0 === i)
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHTML(str) {
|
||||||
|
return str.replace(/[<>&"']/g, function (match) {
|
||||||
|
switch (match) {
|
||||||
|
case '<':
|
||||||
|
return '<'
|
||||||
|
case '>':
|
||||||
|
return '>'
|
||||||
|
case '&':
|
||||||
|
return '&'
|
||||||
|
case '"':
|
||||||
|
return '"'
|
||||||
|
case "'":
|
||||||
|
return '''
|
||||||
|
default:
|
||||||
|
return match
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
class NData {
|
||||||
|
/**
|
||||||
|
* 获取 MD5sum
|
||||||
|
* @param {String} 数据
|
||||||
|
*/
|
||||||
|
static mount(node) {
|
||||||
|
// 便捷获得指定组件
|
||||||
|
let es = node.querySelectorAll("[n-id]")
|
||||||
|
let ls = {}
|
||||||
|
es.forEach((i) => ls[$(i).attr("n-id")] = $(i))
|
||||||
|
|
||||||
|
// input 组件与 localStorage 绑定
|
||||||
|
es = node.querySelectorAll("[n-input-ls]")
|
||||||
|
es.forEach((e) => {
|
||||||
|
let j = $(e)
|
||||||
|
j.val(localStorage.getItem(j.attr("n-input-ls")))
|
||||||
|
j.blur(() => localStorage.setItem(j.attr("n-input-ls"), j.val()))
|
||||||
|
})
|
||||||
|
return ls
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://www.runoob.com/w3cnote/javascript-copy-clipboard.html
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制文字
|
||||||
|
* @param {String} 欲复制的文本
|
||||||
|
*/
|
||||||
|
function copyText(t) {
|
||||||
|
let btn = $("[n-id=textCopierBtn]")
|
||||||
|
btn.attr("data-clipboard-text", t)
|
||||||
|
new ClipboardJS(btn.get(0)).on('success', (e) => {
|
||||||
|
e.clearSelection()
|
||||||
|
})
|
||||||
|
btn.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://zhuanlan.zhihu.com/p/162910462
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期
|
||||||
|
* @param {int} 时间戳
|
||||||
|
* @param {String} 欲格式化的文本
|
||||||
|
* @returns {String} 格式后的文本
|
||||||
|
*/
|
||||||
|
Date.prototype.format = function (tms, format) {
|
||||||
|
let tmd = new Date(tms)
|
||||||
|
/*
|
||||||
|
* 例子: format="YYYY-MM-dd hh:mm:ss";
|
||||||
|
*/
|
||||||
|
var o = {
|
||||||
|
"M+": tmd.getMonth() + 1, // month
|
||||||
|
"d+": tmd.getDate(), // day
|
||||||
|
"h+": tmd.getHours(), // hour
|
||||||
|
"m+": tmd.getMinutes(), // minute
|
||||||
|
"s+": tmd.getSeconds(), // second
|
||||||
|
"q+": Math.floor((tmd.getMonth() + 3) / 3), // quarter
|
||||||
|
"S": tmd.getMilliseconds()
|
||||||
|
// millisecond
|
||||||
|
}
|
||||||
|
if (/(y+)/.test(format)) {
|
||||||
|
format = format.replace(RegExp.$1, (tmd.getFullYear() + "")
|
||||||
|
.substr(4 - RegExp.$1.length));
|
||||||
|
}
|
||||||
|
for (var k in o) {
|
||||||
|
if (new RegExp("(" + k + ")").test(format)) {
|
||||||
|
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
|
||||||
|
: ("00" + o[k]).substr(("" + o[k]).length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 既然已经有 Notification 了, 那用回中文也不过分吧 :)
|
||||||
|
class 通知 {
|
||||||
|
constructor() {
|
||||||
|
this.args = {}
|
||||||
|
this.title = ""
|
||||||
|
}
|
||||||
|
static checkAvailable() {
|
||||||
|
return ("Notification" in window)
|
||||||
|
}
|
||||||
|
static async request() {
|
||||||
|
if (!this.checkAvailable()) return false
|
||||||
|
return (await Notification.requestPermission())
|
||||||
|
}
|
||||||
|
setId(id) {
|
||||||
|
this.args.tag = id
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
setTitle(t) {
|
||||||
|
this.title = t
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
setMessage(m) {
|
||||||
|
this.args.body = m
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
setIcon(i) {
|
||||||
|
this.args.icon = i
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
setImage(i) {
|
||||||
|
this.args.image = i
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
setData(data) {
|
||||||
|
this.args.data = data
|
||||||
|
}
|
||||||
|
show(onclick/*, onclose*/) {
|
||||||
|
if (!通知.checkAvailable()) return
|
||||||
|
if (localStorage.useNotifications !== "true") return
|
||||||
|
let n = new Notification(this.title, this.args)
|
||||||
|
n.onclick = onclick == null ? () => n.close() : (n) => onclick(n)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Hash {
|
||||||
|
/**
|
||||||
|
* 获取 MD5sum
|
||||||
|
* @param {String} 数据
|
||||||
|
* @returns {String} Hex化的哈希值
|
||||||
|
*/
|
||||||
|
static md5(data) {
|
||||||
|
return CryptoJS.MD5(data).toString(CryptoJS.enc.Hex)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取 SHA256sum
|
||||||
|
* @param {String} 数据
|
||||||
|
* @returns {String} Hex化的哈希值
|
||||||
|
*/
|
||||||
|
static sha256(data) {
|
||||||
|
return CryptoJS.SHA256(data).toString(CryptoJS.enc.Hex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.copyText = copyText
|
||||||
|
window.NData = NData
|
||||||
|
window.escapeHTML = escapeHTML
|
||||||
|
window.isMobile = isMobile
|
||||||
|
window.checkEmpty = checkEmpty
|
||||||
|
window.sleep = sleep
|
||||||
|
window.Hash = Hash
|
||||||
|
window.通知 = 通知
|
||||||
555
package-lock.json
generated
555
package-lock.json
generated
@@ -10,9 +10,450 @@
|
|||||||
"license": "Apache License 2.0",
|
"license": "Apache License 2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
|
"sharp": "^0.33.4",
|
||||||
"socket.io": "^4.7.5"
|
"socket.io": "^4.7.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@emnapi/runtime": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-darwin-arm64": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-p0suNqXufJs9t3RqLBO6vvrgr5OhgbWp76s5gTRvdmxmuv9E1rcaqGUsl3l4mKVmXPkTkTErXediAui4x+8PSA==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.26",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-darwin-arm64": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-darwin-x64": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-0l7yRObwtTi82Z6ebVI2PnHT8EB2NxBgpK2MiKJZJ7cz32R4lxd001ecMhzzsZig3Yv9oclvqqdV93jo9hy+Dw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.26",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-darwin-x64": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-darwin-arm64": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-tcK/41Rq8IKlSaKRCCAuuY3lDJjQnYIW1UXU1kxcEKrfL8WR7N6+rzNoOxoQRJWTAECuKwgAHnPvqXGN8XfkHA==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"macos": ">=11",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-darwin-x64": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-Ofw+7oaWa0HiiMiKWqqaZbaYV3/UGL2wAPeLuJTx+9cXpCRdvQhCLG0IH8YGwM0yGWGLpsF4Su9vM1o6aer+Fw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"macos": ">=10.13",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-linux-arm": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-iLWCvrKgeFoglQxdEwzu1eQV04o8YeYGFXtfWU26Zr2wWT3q3MTzC+QTCO3ZQfWd3doKHT4Pm2kRmLbupT+sZw==",
|
||||||
|
"cpu": [
|
||||||
|
"arm"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.28",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-linux-arm64": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-x7kCt3N00ofFmmkkdshwj3vGPCnmiDh7Gwnd4nUwZln2YjqPxV1NlTyZOvoDWdKQVDL911487HOueBvrpflagw==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.26",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-linux-s390x": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-cmhQ1J4qVhfmS6szYW7RT+gLJq9dH2i4maq+qyXayUSn9/3iY2ZeWpbAgSpSVbV2E1JUL2Gg7pwnYQ1h8rQIog==",
|
||||||
|
"cpu": [
|
||||||
|
"s390x"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.28",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-linux-x64": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-E441q4Qdb+7yuyiADVi5J+44x8ctlrqn8XgkDTwr4qPJzWkaHwD489iZ4nGDgcuya4iMN3ULV6NwbhRZJ9Z7SQ==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.26",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-linuxmusl-arm64": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-3CAkndNpYUrlDqkCM5qhksfE+qSIREVpyoeHIU6jd48SJZViAmznoQQLAv4hVXF7xyUB9zf+G++e2v1ABjCbEQ==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"musl": ">=1.2.2",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-libvips-linuxmusl-x64": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-VI94Q6khIHqHWNOh6LLdm9s2Ry4zdjWJwH56WoiJU7NTeDwyApdZZ8c+SADC8OH98KWNQXnE01UdJ9CSfZvwZw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"musl": ">=1.2.2",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-linux-arm": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-RUgBD1c0+gCYZGCCe6mMdTiOFS0Zc/XrN0fYd6hISIKcDUbAW5NtSQW9g/powkrXYm6Vzwd6y+fqmExDuCdHNQ==",
|
||||||
|
"cpu": [
|
||||||
|
"arm"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.28",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-arm": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-linux-arm64": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-2800clwVg1ZQtxwSoTlHvtm9ObgAax7V6MTAB/hDT945Tfyy3hVkmiHpeLPCKYqYR1Gcmv1uDZ3a4OFwkdBL7Q==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.26",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-arm64": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-linux-s390x": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-h3RAL3siQoyzSoH36tUeS0PDmb5wINKGYzcLB5C6DIiAn2F3udeFAum+gj8IbA/82+8RGCTn7XW8WTFnqag4tQ==",
|
||||||
|
"cpu": [
|
||||||
|
"s390x"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.31",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-s390x": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-linux-x64": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-GoR++s0XW9DGVi8SUGQ/U4AeIzLdNjHka6jidVwapQ/JebGVQIpi52OdyxCNVRE++n1FCLzjDovJNozif7w/Aw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"glibc": ">=2.26",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-x64": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-linuxmusl-arm64": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-nhr1yC3BlVrKDTl6cO12gTpXMl4ITBUZieehFvMntlCXFzH2bvKG76tBL2Y/OqhupZt81pR7R+Q5YhJxW0rGgQ==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"musl": ">=1.2.2",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linuxmusl-arm64": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-linuxmusl-x64": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-uCPTku0zwqDmZEOi4ILyGdmW76tH7dm8kKlOIV1XC5cLyJ71ENAAqarOHQh0RLfpIpbV5KOpXzdU6XkJtS0daw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"musl": ">=1.2.2",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linuxmusl-x64": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-wasm32": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-Bmmauh4sXUsUqkleQahpdNXKvo+wa1V9KhT2pDA4VJGKwnKMJXiSTGphn0gnJrlooda0QxCtXc6RX1XAU6hMnQ==",
|
||||||
|
"cpu": [
|
||||||
|
"wasm32"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@emnapi/runtime": "^1.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-win32-ia32": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-99SJ91XzUhYHbx7uhK3+9Lf7+LjwMGQZMDlO/E/YVJ7Nc3lyDFZPGhjwiYdctoH2BOzW9+TnfqcaMKt0jHLdqw==",
|
||||||
|
"cpu": [
|
||||||
|
"ia32"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@img/sharp-win32-x64": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-3QLocdTRVIrFNye5YocZl+KKpYKP+fksi1QhmOArgx7GyhIbQp/WrJRu176jm8IxromS7RIkzMiMINVdBtC8Aw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
"npm": ">=9.6.5",
|
||||||
|
"pnpm": ">=7.1.0",
|
||||||
|
"yarn": ">=3.2.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@socket.io/component-emitter": {
|
"node_modules/@socket.io/component-emitter": {
|
||||||
"version": "3.1.2",
|
"version": "3.1.2",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
@@ -114,6 +555,43 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/color": {
|
||||||
|
"version": "4.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
|
||||||
|
"integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==",
|
||||||
|
"dependencies": {
|
||||||
|
"color-convert": "^2.0.1",
|
||||||
|
"color-string": "^1.9.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.5.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-convert": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"color-name": "~1.1.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=7.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||||
|
},
|
||||||
|
"node_modules/color-string": {
|
||||||
|
"version": "1.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz",
|
||||||
|
"integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==",
|
||||||
|
"dependencies": {
|
||||||
|
"color-name": "^1.0.0",
|
||||||
|
"simple-swizzle": "^0.2.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/content-disposition": {
|
"node_modules/content-disposition": {
|
||||||
"version": "0.5.4",
|
"version": "0.5.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -198,6 +676,14 @@
|
|||||||
"npm": "1.2.8000 || >= 1.4.16"
|
"npm": "1.2.8000 || >= 1.4.16"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/detect-libc": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ee-first": {
|
"node_modules/ee-first": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
@@ -472,6 +958,11 @@
|
|||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/is-arrayish": {
|
||||||
|
"version": "0.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",
|
||||||
|
"integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="
|
||||||
|
},
|
||||||
"node_modules/media-typer": {
|
"node_modules/media-typer": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -629,6 +1120,17 @@
|
|||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/semver": {
|
||||||
|
"version": "7.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz",
|
||||||
|
"integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==",
|
||||||
|
"bin": {
|
||||||
|
"semver": "bin/semver.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/send": {
|
"node_modules/send": {
|
||||||
"version": "0.18.0",
|
"version": "0.18.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -698,6 +1200,45 @@
|
|||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/sharp": {
|
||||||
|
"version": "0.33.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.4.tgz",
|
||||||
|
"integrity": "sha512-7i/dt5kGl7qR4gwPRD2biwD2/SvBn3O04J77XKFgL2OnZtQw+AG9wnuS/csmu80nPRHLYE9E41fyEiG8nhH6/Q==",
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"dependencies": {
|
||||||
|
"color": "^4.2.3",
|
||||||
|
"detect-libc": "^2.0.3",
|
||||||
|
"semver": "^7.6.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"libvips": ">=8.15.2",
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-darwin-arm64": "0.33.4",
|
||||||
|
"@img/sharp-darwin-x64": "0.33.4",
|
||||||
|
"@img/sharp-libvips-darwin-arm64": "1.0.2",
|
||||||
|
"@img/sharp-libvips-darwin-x64": "1.0.2",
|
||||||
|
"@img/sharp-libvips-linux-arm": "1.0.2",
|
||||||
|
"@img/sharp-libvips-linux-arm64": "1.0.2",
|
||||||
|
"@img/sharp-libvips-linux-s390x": "1.0.2",
|
||||||
|
"@img/sharp-libvips-linux-x64": "1.0.2",
|
||||||
|
"@img/sharp-libvips-linuxmusl-arm64": "1.0.2",
|
||||||
|
"@img/sharp-libvips-linuxmusl-x64": "1.0.2",
|
||||||
|
"@img/sharp-linux-arm": "0.33.4",
|
||||||
|
"@img/sharp-linux-arm64": "0.33.4",
|
||||||
|
"@img/sharp-linux-s390x": "0.33.4",
|
||||||
|
"@img/sharp-linux-x64": "0.33.4",
|
||||||
|
"@img/sharp-linuxmusl-arm64": "0.33.4",
|
||||||
|
"@img/sharp-linuxmusl-x64": "0.33.4",
|
||||||
|
"@img/sharp-wasm32": "0.33.4",
|
||||||
|
"@img/sharp-win32-ia32": "0.33.4",
|
||||||
|
"@img/sharp-win32-x64": "0.33.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/side-channel": {
|
"node_modules/side-channel": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -714,6 +1255,14 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/simple-swizzle": {
|
||||||
|
"version": "0.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
|
||||||
|
"integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==",
|
||||||
|
"dependencies": {
|
||||||
|
"is-arrayish": "^0.3.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/socket.io": {
|
"node_modules/socket.io": {
|
||||||
"version": "4.7.5",
|
"version": "4.7.5",
|
||||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz",
|
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz",
|
||||||
@@ -764,6 +1313,12 @@
|
|||||||
"node": ">=0.6"
|
"node": ">=0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tslib": {
|
||||||
|
"version": "2.6.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
|
||||||
|
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==",
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"node_modules/type-is": {
|
"node_modules/type-is": {
|
||||||
"version": "1.6.18",
|
"version": "1.6.18",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
|
"sharp": "^0.33.4",
|
||||||
"socket.io": "^4.7.5"
|
"socket.io": "^4.7.5"
|
||||||
},
|
},
|
||||||
"type": "commonjs"
|
"type": "commonjs"
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ const vals = require("./val")
|
|||||||
const color = require("./color")
|
const color = require("./color")
|
||||||
|
|
||||||
//定义 Http 服务器回调
|
//定义 Http 服务器回调
|
||||||
let httpServerCallback = require("./httpApi")
|
let httpServerCallback = require("./http-api")
|
||||||
|
|
||||||
// 定义 Socket.io 服务器回调
|
// 定义 Socket.io 服务器回调
|
||||||
let wsServerCallback = require("./wsApi")
|
let wsServerCallback = require("./ws-api")
|
||||||
|
|
||||||
let httpServer
|
let httpServer
|
||||||
if (vals.LINGCHAIR_SERVER_CONFIG.useHttps)
|
if (vals.LINGCHAIR_SERVER_CONFIG.useHttps)
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ if (!io.exists(vals.LINGCHAIR_SERVER_CONFIG_FILE)) io.open(vals.LINGCHAIR_SERVER
|
|||||||
cert: "",
|
cert: "",
|
||||||
},
|
},
|
||||||
})).close()
|
})).close()
|
||||||
if (!io.exists(vals.LINGCHAIR_USERS_COUNT_FILE)) io.open(vals.LINGCHAIR_USERS_COUNT_FILE, "w").write("10000").close()
|
if (!io.exists(vals.LINGCHAIR_USERS_COUNT_FILE))
|
||||||
|
io.open(vals.LINGCHAIR_USERS_COUNT_FILE, "w").write("10000").close()
|
||||||
|
|
||||||
// 加载服务端配置文件
|
// 加载服务端配置文件
|
||||||
vals.LINGCHAIR_SERVER_CONFIG = JSON.parse(io.open(vals.LINGCHAIR_SERVER_CONFIG_FILE, "r").read("*a"))
|
vals.LINGCHAIR_SERVER_CONFIG = JSON.parse(io.open(vals.LINGCHAIR_SERVER_CONFIG_FILE, "r").read("*a"))
|
||||||
|
|||||||
Reference in New Issue
Block a user