最後活躍 1726890905

基于鹊楠改进的Hexo-butterfly聊天记录外挂标签

chat.js 原始檔案
1/**
2 * Chat
3 */
4
5"use strict";
6
7// 预定义头像数组
8const avatars = [
9 "https://i.p-i.vip/30/20240920-66ed9a608c2cf.png",
10 "https://i.p-i.vip/30/20240920-66ed9b0655cba.png",
11 "https://i.p-i.vip/30/20240920-66ed9b18a56ee.png",
12 "https://i.p-i.vip/30/20240920-66ed9b2c199bf.png",
13 "https://i.p-i.vip/30/20240920-66ed9b3350ed1.png",
14 "https://i.p-i.vip/30/20240920-66ed9b5181630.png",
15 // 可以继续添加更多头像
16];
17
18// 用来记录已经分配头像的用户
19const userAvatarMap = new Map();
20let avatarIndex = 0;
21
22// 生成聊天框的整体结构
23function postChatBox(args, content) {
24 const title = args[0] ? args[0].trim() : "群聊的聊天记录"; // 获取标题
25 const titleHtml = title ? `<div class="chatBoxTitle"><i class="fa-solid fa-angle-left"></i><span class="chatTitleText">${title}</span><div class="chatBoxIcons"><i class="fa-solid fa-user"></i><i class="fa-solid fa-bars"></i></div></div>` : ""; // 生成标题 HTML
26 const contentHtml = `<div class="chatBox">${content}</div>`
27 return `<div class="chatContainer">${titleHtml}${contentHtml}</div>`;
28}
29
30// 生成单条聊天内容
31function postChat(args) {
32 if (!args || args.length === 0) {
33 return ""; // 如果参数为空,返回空字符串
34 }
35
36 // 合并并拆分参数
37 args = args.join(" ").split(",");
38
39 // 确保 args[0] 存在
40 let name = args[0] ? args[0].trim() : "未知";
41 let content = args[1] ? args[1].trim() : "无内容";
42
43 // 判断名字是否包含 QQ 号 (例如 June@3526514925)
44 let qqNumber = null;
45 if (name.includes("@")) {
46 [name, qqNumber] = name.split("@"); // 分割名字和 QQ 号
47 }
48
49 // 判断是否是我的消息
50 const isMe = name.toLowerCase() === "me";
51 const chatName = isMe ? hexo.config.author : name;
52 const chatClass = isMe ? "me" : "";
53
54 // 固定的头像链接
55 const myAvatar = "https://cdn.qyliu.top/i/2024/03/29/66061417537af.png";
56 let avatarUrl;
57
58 if (isMe) {
59 avatarUrl = myAvatar;
60 } else if (qqNumber) {
61 // 如果有 QQ 号,拼接头像 URL
62 avatarUrl = `https://q1.qlogo.cn/g?b=qq&nk=${qqNumber}&s=100`;
63 } else {
64 // 如果没有 QQ 号,从预定义的头像数组中分配
65 if (!userAvatarMap.has(name)) {
66 userAvatarMap.set(name, avatars[avatarIndex % avatars.length]);
67 avatarIndex++;
68 }
69 avatarUrl = userAvatarMap.get(name);
70 }
71
72 // 生成 HTML 布局
73 let result = "";
74 result += `<div class="chatItem ${chatClass}">`;
75 result += `<img class="chatAvatar no-lightbox" src="${avatarUrl}">`; // 添加头像
76 result += `<div class="chatContentWrapper">`;
77 result += `<b class="chatName">${chatName}</b>`;
78 result += `<div class="chatContent">${content}</div>`;
79 result += `</div>`;
80 result += `</div>`;
81
82 return result;
83}
84
85// 注册自定义标签
86hexo.extend.tag.register("chat", postChat);
87hexo.extend.tag.register("chatBox", postChatBox, { ends: true });
chat.styl 原始檔案
1.chatContainer
2 @extend .cardHover
3 overflow: hidden
4 width: 100%
5
6 .chatBoxTitle
7 display: flex
8 justify-content: flex-start
9 background: var(--default-bg-color)
10 padding: 10px 10px
11 color: var(--white)
12 display: flex
13 align-items: center
14 justify-content: space-between
15
16 i
17 font-size: 16px
18 margin: 0 10px
19
20 .chatTitleText
21 flex: 1
22 font-size: 16px
23 white-space: nowrap; /* */
24 overflow: hidden; /* */
25 text-overflow: ellipsis; /* */
26
27.chatBox
28 padding: 20px 30px
29 box-sizing: border-box
30
31 +maxWidth768()
32 padding: 20px 10px
33
34.chatItem
35 display: flex
36 flex-direction: row
37 justify-content: flex-start
38 margin: 20px 0
39
40 .chatAvatar
41 width: 40px
42 height: 40px
43 border-radius: 50% !important
44 margin: 5px 10px 0 0 !important
45
46 .chatContentWrapper
47 display: flex
48 flex-direction: column
49 width: calc(100% - 110px)
50
51 .chatContent
52 background: var(--liushen-card-secondbg)
53 border: 1px solid var(--liushen-card-border)
54 padding: 10px
55 border-radius: 0 10px 10px 10px
56 width: fit-content
57 max-width: 100%
58 word-wrap: break-word
59
60 &.me
61 flex-direction: row-reverse
62
63 .chatAvatar
64 margin: 5px 0 0 10px !important
65
66 .chatContentWrapper
67 align-items: flex-end
68
69 .chatContent
70 background: var(--liushen-card-bg)
71 border-radius: 10px 0 10px 10px