hexo-theme-solitude 1.7.13 → 1.7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_config.yml +7 -3
- package/languages/en.yml +4 -0
- package/languages/zh-CN.yml +4 -0
- package/languages/zh-TW.yml +4 -0
- package/layout/includes/head/config.pug +5 -0
- package/layout/includes/inject/body.pug +8 -11
- package/layout/includes/inject/head.pug +8 -35
- package/layout/includes/widgets/nav/right.pug +4 -41
- package/layout/includes/widgets/post/postMeta.pug +6 -0
- package/layout/includes/widgets/third-party/comments/artalk.pug +50 -0
- package/layout/includes/widgets/third-party/comments/comment.pug +3 -1
- package/layout/includes/widgets/third-party/comments/twikoo.pug +31 -2
- package/layout/includes/widgets/third-party/comments/valine.pug +44 -12
- package/layout/includes/widgets/third-party/comments/waline.pug +41 -14
- package/layout/includes/widgets/third-party/news-comment/artalk.pug +98 -0
- package/layout/includes/widgets/third-party/news-comment/newest-comment.pug +3 -1
- package/layout/includes/widgets/third-party/news-comment/twikoo.pug +7 -7
- package/layout/includes/widgets/third-party/news-comment/valine.pug +3 -3
- package/layout/includes/widgets/third-party/news-comment/waline.pug +3 -3
- package/package.json +1 -1
- package/plugins.yml +8 -4
- package/scripts/event/cdn.js +2 -12
- package/source/css/_layout/header.styl +48 -48
- package/source/js/barrage_comment.js +78 -0
- package/source/js/main.js +46 -1
- package/source/js/third_party/efu_ai.min.js +1 -1
- package/source/js/commentBarrage/twikoo.js +0 -151
- package/source/js/commentBarrage/valine.js +0 -156
- package/source/js/commentBarrage/waline.js +0 -153
@@ -1,153 +0,0 @@
|
|
1
|
-
function initializeCommentBarrage() {
|
2
|
-
window.commentBarrageInitialized = !0;
|
3
|
-
let config = {
|
4
|
-
maxBarrage: 1,
|
5
|
-
barrageTime: 8e3,
|
6
|
-
walineUrl: GLOBAL_CONFIG.comment.url,
|
7
|
-
pageUrl: window.location.pathname,
|
8
|
-
}
|
9
|
-
new class {
|
10
|
-
commentInterval = null
|
11
|
-
|
12
|
-
constructor(config) {
|
13
|
-
this.config = {
|
14
|
-
...config,
|
15
|
-
barrageTimer: [],
|
16
|
-
barrageList: [],
|
17
|
-
barrageIndex: 0,
|
18
|
-
dom: document.querySelector(".comment-barrage")
|
19
|
-
};
|
20
|
-
this.commentInterval = null;
|
21
|
-
this.hoverOnCommentBarrage = false;
|
22
|
-
this.init();
|
23
|
-
}
|
24
|
-
|
25
|
-
async fetchComments() {
|
26
|
-
const url = new URL(`${this.config.walineUrl}/api/comment`);
|
27
|
-
const params = {
|
28
|
-
path: this.config.pageUrl,
|
29
|
-
sortBy: 'insertedAt_asc'
|
30
|
-
};
|
31
|
-
|
32
|
-
for (const [key, value] of Object.entries(params)) {
|
33
|
-
url.searchParams.append(key, value);
|
34
|
-
}
|
35
|
-
|
36
|
-
try {
|
37
|
-
const response = await fetch(url, {
|
38
|
-
method: "GET",
|
39
|
-
headers: {
|
40
|
-
"Content-Type": "application/json"
|
41
|
-
},
|
42
|
-
});
|
43
|
-
|
44
|
-
if (!response.ok) {
|
45
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
46
|
-
}
|
47
|
-
|
48
|
-
const data = await response.json();
|
49
|
-
return data.data;
|
50
|
-
} catch (error) {
|
51
|
-
console.error("An error occurred while fetching comments: ", error);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
commentLinkFilter(comments) {
|
56
|
-
return comments.data.flatMap(comment => this.getCommentReplies(comment));
|
57
|
-
}
|
58
|
-
|
59
|
-
getCommentReplies(comment) {
|
60
|
-
if (!comment.replies) {
|
61
|
-
return [comment];
|
62
|
-
}
|
63
|
-
return [comment, ...comment.replies.flatMap(reply => this.getCommentReplies(reply))];
|
64
|
-
}
|
65
|
-
|
66
|
-
processCommentContent(comment) {
|
67
|
-
const processed = comment.replace(/<blockquote\b[^>]*>[\s\S]*?<\/blockquote>|<[^>]*>|\n/g, "").trim();
|
68
|
-
return processed ? `<p>${processed}</p>` : "";
|
69
|
-
}
|
70
|
-
|
71
|
-
createCommentBarrage(comment) {
|
72
|
-
const content = this.processCommentContent(comment.comment).trim();
|
73
|
-
if (!content) {
|
74
|
-
return false;
|
75
|
-
}
|
76
|
-
|
77
|
-
const element = document.createElement("div");
|
78
|
-
element.classList.add("comment-barrage-item");
|
79
|
-
element.innerHTML = `
|
80
|
-
<div class="barrageHead">
|
81
|
-
<a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">${GLOBAL_CONFIG.lang.barrage.title}</a>
|
82
|
-
<div class="barrageNick">${comment.nick}</div>
|
83
|
-
<img class="barrageAvatar" src="${GLOBAL_CONFIG.comment.avatar}/avatar/${comment.avatar}"/>
|
84
|
-
<a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();">
|
85
|
-
<i class="solitude st-close-fill"></i>
|
86
|
-
</a>
|
87
|
-
</div>
|
88
|
-
<a class="barrageContent" href="javascript:sco.scrollTo('${comment.objectId}');">${comment.comment}</a>
|
89
|
-
`;
|
90
|
-
|
91
|
-
this.config.dom.appendChild(element);
|
92
|
-
this.config.barrageTimer.push(element);
|
93
|
-
|
94
|
-
return true;
|
95
|
-
}
|
96
|
-
|
97
|
-
removeCommentBarrage(element) {
|
98
|
-
element.className = "comment-barrage-item out";
|
99
|
-
setTimeout(() => {
|
100
|
-
this.config.dom.removeChild(element);
|
101
|
-
}, 1000);
|
102
|
-
}
|
103
|
-
|
104
|
-
async initCommentBarrage() {
|
105
|
-
const commentBarrage = document.querySelector(".comment-barrage");
|
106
|
-
const menuCommentBarrageText = document.querySelector(".menu-commentBarrage-text");
|
107
|
-
const consoleCommentBarrage = document.querySelector("#consoleCommentBarrage");
|
108
|
-
|
109
|
-
if (localStorage.getItem("commentBarrageSwitch") != null) {
|
110
|
-
commentBarrage.style.display = "flex";
|
111
|
-
consoleCommentBarrage.classList.add("on");
|
112
|
-
} else {
|
113
|
-
commentBarrage.style.display = "none";
|
114
|
-
consoleCommentBarrage.classList.remove("on");
|
115
|
-
}
|
116
|
-
|
117
|
-
const comments = await this.fetchComments();
|
118
|
-
this.config.barrageList = this.commentLinkFilter(comments);
|
119
|
-
this.config.dom.innerHTML = "";
|
120
|
-
clearInterval(this.commentInterval);
|
121
|
-
this.commentInterval = null;
|
122
|
-
|
123
|
-
const createOrRemoveBarrage = () => {
|
124
|
-
if (this.config.barrageList.length && !this.hoverOnCommentBarrage) {
|
125
|
-
if (!this.createCommentBarrage(this.config.barrageList[this.config.barrageIndex])) {
|
126
|
-
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
127
|
-
return createOrRemoveBarrage();
|
128
|
-
}
|
129
|
-
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
130
|
-
}
|
131
|
-
if (this.config.barrageTimer.length > (this.config.barrageList.length > this.config.maxBarrage ? this.config.maxBarrage : this.config.barrageList.length) && !this.hoverOnCommentBarrage) {
|
132
|
-
this.removeCommentBarrage(this.config.barrageTimer.shift());
|
133
|
-
}
|
134
|
-
};
|
135
|
-
|
136
|
-
setTimeout(() => {
|
137
|
-
createOrRemoveBarrage();
|
138
|
-
if (this.commentInterval) {
|
139
|
-
clearInterval(this.commentInterval);
|
140
|
-
}
|
141
|
-
this.commentInterval = setInterval(createOrRemoveBarrage, this.config.barrageTime);
|
142
|
-
}, 3000);
|
143
|
-
}
|
144
|
-
|
145
|
-
async init() {
|
146
|
-
await this.initCommentBarrage();
|
147
|
-
const commentBarrage = document.querySelector(".comment-barrage");
|
148
|
-
commentBarrage.addEventListener('mouseover', () => this.hoverOnCommentBarrage = true);
|
149
|
-
commentBarrage.addEventListener('mouseout', () => this.hoverOnCommentBarrage = false);
|
150
|
-
}
|
151
|
-
}
|
152
|
-
(config)
|
153
|
-
}
|