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
package/package.json
CHANGED
package/plugins.yml
CHANGED
@@ -27,10 +27,14 @@ valine:
|
|
27
27
|
name: valine
|
28
28
|
file: dist/Valine.min.js
|
29
29
|
version: 1.5.1
|
30
|
-
|
31
|
-
name:
|
32
|
-
file:
|
33
|
-
version:
|
30
|
+
artalk_css:
|
31
|
+
name: artalk
|
32
|
+
file: Artalk.css
|
33
|
+
version: 2.8.4
|
34
|
+
artalk_js:
|
35
|
+
name: artalk
|
36
|
+
file: Artalk.js
|
37
|
+
version: 2.8.4
|
34
38
|
katex:
|
35
39
|
name: katex
|
36
40
|
file: dist/katex.min.css
|
package/scripts/event/cdn.js
CHANGED
@@ -64,19 +64,9 @@ hexo.extend.filter.register('before_generate', () => {
|
|
64
64
|
file: 'js/third_party/efu_ai.min.js',
|
65
65
|
version
|
66
66
|
},
|
67
|
-
|
67
|
+
commentBarrage: {
|
68
68
|
name: 'hexo-theme-solitude',
|
69
|
-
file: 'js/
|
70
|
-
version
|
71
|
-
},
|
72
|
-
waline_commentBarrage: {
|
73
|
-
name: 'hexo-theme-solitude',
|
74
|
-
file: 'js/commentBarrage/waline.js',
|
75
|
-
version
|
76
|
-
},
|
77
|
-
valine_commentBarrage: {
|
78
|
-
name: 'hexo-theme-solitude',
|
79
|
-
file: 'js/commentBarrage/valine.js',
|
69
|
+
file: 'js/barrage_comment.js',
|
80
70
|
version
|
81
71
|
},
|
82
72
|
waterfall: {
|
@@ -267,17 +267,17 @@
|
|
267
267
|
|
268
268
|
&.no-top-img
|
269
269
|
margin-bottom 0
|
270
|
-
if hexo-config('nav.right.top')
|
271
|
-
&:not(.nav-fixed)
|
272
|
-
#percent
|
273
|
-
transition .3s
|
274
270
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
271
|
+
&:not(.nav-fixed)
|
272
|
+
#percent
|
273
|
+
transition .3s
|
274
|
+
|
275
|
+
#nav-right #nav-totop
|
276
|
+
width 0
|
277
|
+
transform scale(0)
|
278
|
+
margin-left 0
|
279
|
+
overflow hidden
|
280
|
+
transition .3s ease-in
|
281
281
|
|
282
282
|
#page-header #scroll-down .scroll-down-effects,
|
283
283
|
#page-header #site-subtitle, #page-header #site-title
|
@@ -606,51 +606,40 @@
|
|
606
606
|
#site-logo
|
607
607
|
width 121px
|
608
608
|
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
align-items center
|
618
|
-
|
619
|
-
&.long
|
620
|
-
width 80px
|
609
|
+
#nav-totop
|
610
|
+
position relative
|
611
|
+
width 35px
|
612
|
+
height 35px
|
613
|
+
display flex
|
614
|
+
border-radius 40px
|
615
|
+
transition all .3s ease-in-out
|
616
|
+
align-items center
|
621
617
|
|
622
|
-
|
623
|
-
|
618
|
+
&.long
|
619
|
+
width 80px
|
624
620
|
|
625
|
-
|
626
|
-
|
627
|
-
display flex
|
628
|
-
font-size 22px
|
629
|
-
opacity 0
|
630
|
-
line-height 1
|
621
|
+
.totopbtn
|
622
|
+
padding-top 0
|
631
623
|
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
624
|
+
i
|
625
|
+
position absolute
|
626
|
+
display flex
|
627
|
+
font-size 22px
|
628
|
+
opacity 0
|
629
|
+
line-height 1
|
638
630
|
|
639
|
-
|
640
|
-
|
641
|
-
|
631
|
+
&:hover
|
632
|
+
.totopbtn
|
633
|
+
i
|
634
|
+
opacity 1
|
635
|
+
color var(--efu-card-bg)
|
636
|
+
transition .3s
|
642
637
|
|
643
638
|
#percent
|
644
|
-
|
645
|
-
|
646
|
-
display flex
|
647
|
-
justify-content center
|
648
|
-
align-items center
|
649
|
-
transition .3s
|
650
|
-
white-space nowrap
|
639
|
+
opacity 0
|
640
|
+
font-weight 700
|
651
641
|
|
652
|
-
|
653
|
-
.page #nav-totop #percent
|
642
|
+
#percent
|
654
643
|
font-size 12px
|
655
644
|
border-radius 35px
|
656
645
|
display flex
|
@@ -659,6 +648,16 @@ if hexo-config('nav.right.top')
|
|
659
648
|
transition .3s
|
660
649
|
white-space nowrap
|
661
650
|
|
651
|
+
.nav-fixed #nav-totop #percent,
|
652
|
+
.page #nav-totop #percent
|
653
|
+
font-size 12px
|
654
|
+
border-radius 35px
|
655
|
+
display flex
|
656
|
+
justify-content center
|
657
|
+
align-items center
|
658
|
+
transition .3s
|
659
|
+
white-space nowrap
|
660
|
+
|
662
661
|
if hexo-config('nav.group')
|
663
662
|
.back-home-button
|
664
663
|
display flex
|
@@ -847,6 +846,7 @@ if hexo-config('nav.group')
|
|
847
846
|
background var(--efu-main)
|
848
847
|
transition .3s
|
849
848
|
box-shadow var(--efu-shadow-main)
|
849
|
+
|
850
850
|
#site-name
|
851
851
|
&:hover
|
852
852
|
i
|
@@ -0,0 +1,78 @@
|
|
1
|
+
/**
|
2
|
+
* Comment Barrage
|
3
|
+
* author: @efu
|
4
|
+
* website: efu.me
|
5
|
+
* copyright: MIT
|
6
|
+
* date: 2024-04-12
|
7
|
+
* update: 2024-04-12
|
8
|
+
* @param array
|
9
|
+
*/
|
10
|
+
function initializeCommentBarrage(array) {
|
11
|
+
if (array === undefined) return;
|
12
|
+
new class {
|
13
|
+
constructor() {
|
14
|
+
this.config = {
|
15
|
+
barrageTimer: [],
|
16
|
+
barrageList: [],
|
17
|
+
barrageIndex: 0,
|
18
|
+
dom: document.querySelector(".comment-barrage"),
|
19
|
+
maxBarrage: 1,
|
20
|
+
barrageTime: 5000
|
21
|
+
};
|
22
|
+
this.hoverOnCommentBarrage = false;
|
23
|
+
this.init();
|
24
|
+
}
|
25
|
+
|
26
|
+
filterAndFlatten(comments) {
|
27
|
+
return comments.flatMap(comment => comment.replies ? [comment, ...this.filterAndFlatten(comment.replies)] : [comment]);
|
28
|
+
}
|
29
|
+
|
30
|
+
sanitizeContent(content) {
|
31
|
+
return content.replace(/(<([^>]+)>)/ig, '').trim();
|
32
|
+
}
|
33
|
+
|
34
|
+
createBarrageItem(comment) {
|
35
|
+
const content = this.sanitizeContent(comment.content);
|
36
|
+
if (!content) return false;
|
37
|
+
const element = document.createElement("div");
|
38
|
+
element.className = "comment-barrage-item";
|
39
|
+
element.innerHTML = `<div class="barrageHead"><a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">${GLOBAL_CONFIG.lang.barrage.title}</a><div class="barrageNick">${comment.nick}</div><img class="barrageAvatar" src="${GLOBAL_CONFIG.comment.avatar}/avatar/${comment.mailMd5}"/><a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();"><i class="solitude st-close-fill"></i></a></div><a class="barrageContent" href="${comment.id ? `javascript:sco.scrollTo(\'${comment.id}\')` : 'javascript:sco.scrollTo(\'post-comment\')' }">${content}</a>`;
|
40
|
+
this.config.dom.appendChild(element);
|
41
|
+
this.config.barrageTimer.push(element);
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
|
45
|
+
removeBarrageItem(element) {
|
46
|
+
element.classList.add("out");
|
47
|
+
setTimeout(() => this.config.dom.removeChild(element), 1000);
|
48
|
+
}
|
49
|
+
|
50
|
+
manageBarrage() {
|
51
|
+
if (this.config.barrageList.length && !this.hoverOnCommentBarrage) {
|
52
|
+
if (!this.createBarrageItem(this.config.barrageList[this.config.barrageIndex])) {
|
53
|
+
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
54
|
+
return this.manageBarrage();
|
55
|
+
}
|
56
|
+
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
57
|
+
}
|
58
|
+
if (this.config.barrageTimer.length > Math.min(this.config.maxBarrage, this.config.barrageList.length) && !this.hoverOnCommentBarrage) {
|
59
|
+
this.removeBarrageItem(this.config.barrageTimer.shift());
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
async initBarrage() {
|
64
|
+
const storageSwitch = localStorage.getItem("commentBarrageSwitch");
|
65
|
+
this.config.dom.style.display = storageSwitch ? "flex" : "none";
|
66
|
+
this.config.barrageList = this.filterAndFlatten(array);
|
67
|
+
this.config.dom.innerHTML = "";
|
68
|
+
clearInterval(this.commentInterval);
|
69
|
+
this.commentInterval = setInterval(() => this.manageBarrage(), this.config.barrageTime);
|
70
|
+
}
|
71
|
+
|
72
|
+
async init() {
|
73
|
+
await this.initBarrage();
|
74
|
+
this.config.dom.addEventListener('mouseover', () => this.hoverOnCommentBarrage = true);
|
75
|
+
this.config.dom.addEventListener('mouseout', () => this.hoverOnCommentBarrage = false);
|
76
|
+
}
|
77
|
+
}();
|
78
|
+
}
|
package/source/js/main.js
CHANGED
@@ -63,6 +63,50 @@ const scrollFn = function () {
|
|
63
63
|
}
|
64
64
|
}
|
65
65
|
|
66
|
+
const percent = () => {
|
67
|
+
let scrollTop = document.documentElement.scrollTop || window.pageYOffset
|
68
|
+
let totalHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight) - document.documentElement.clientHeight
|
69
|
+
let scrollPercent = Math.round(scrollTop / totalHeight * 100)
|
70
|
+
let percentElement = document.querySelector("#percent")
|
71
|
+
let viewportBottom = window.scrollY + document.documentElement.clientHeight
|
72
|
+
let remainingScroll = totalHeight - scrollTop
|
73
|
+
|
74
|
+
if ((document.getElementById("post-comment") || document.getElementById("footer")).offsetTop < viewportBottom || scrollPercent > 90) {
|
75
|
+
document.querySelector("#nav-totop").classList.add("long")
|
76
|
+
percentElement.innerHTML = GLOBAL_CONFIG.lang.backtop
|
77
|
+
} else {
|
78
|
+
document.querySelector("#nav-totop").classList.remove("long")
|
79
|
+
if (scrollPercent >= 0) {
|
80
|
+
percentElement.innerHTML = scrollPercent + ""
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
let elementsToHide = document.querySelectorAll(".needEndHide")
|
85
|
+
if (remainingScroll < 100) {
|
86
|
+
elementsToHide.forEach(function (element) {
|
87
|
+
element.classList.add("hide")
|
88
|
+
})
|
89
|
+
} else {
|
90
|
+
elementsToHide.forEach(function (element) {
|
91
|
+
element.classList.remove("hide")
|
92
|
+
})
|
93
|
+
}
|
94
|
+
|
95
|
+
window.onscroll = percent
|
96
|
+
}
|
97
|
+
|
98
|
+
const handleThemeChange = mode => {
|
99
|
+
const globalFn = window.globalFn || {}
|
100
|
+
const themeChange = globalFn.themeChange || {}
|
101
|
+
if (!themeChange) {
|
102
|
+
return
|
103
|
+
}
|
104
|
+
|
105
|
+
Object.keys(themeChange).forEach(key => {
|
106
|
+
const themeChangeFn = themeChange[key]
|
107
|
+
themeChangeFn(mode)
|
108
|
+
})
|
109
|
+
}
|
66
110
|
|
67
111
|
const showTodayCard = () => {
|
68
112
|
const el = document.getElementById('todayCard')
|
@@ -282,6 +326,7 @@ let sco = {
|
|
282
326
|
utils.snackbarShow(GLOBAL_CONFIG.lang.theme.light, false, 2000)
|
283
327
|
right_menu && rm.mode(false)
|
284
328
|
}
|
329
|
+
handleThemeChange(nowMode)
|
285
330
|
},
|
286
331
|
hideTodayCard: () => document.getElementById('todayCard').classList.add('hide'),
|
287
332
|
toTop: () => utils.scrollToDest(0),
|
@@ -791,6 +836,7 @@ class tabs {
|
|
791
836
|
}
|
792
837
|
|
793
838
|
sco.initAdjust()
|
839
|
+
percent()
|
794
840
|
initObserver()
|
795
841
|
addCopyright()
|
796
842
|
sco.initConsoleState()
|
@@ -821,7 +867,6 @@ window.refreshFn = () => {
|
|
821
867
|
(PAGE_CONFIG.is_post || PAGE_CONFIG.is_page) && ((addHighlight()) || tabs.init())
|
822
868
|
PAGE_CONFIG.is_home && showTodayCard()
|
823
869
|
GLOBAL_CONFIG.covercolor.enable && coverColor()
|
824
|
-
GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage()
|
825
870
|
PAGE_CONFIG.page === "music" && scoMusic.init()
|
826
871
|
GLOBAL_CONFIG.post_ai && PAGE_CONFIG.page === "post" && efu_ai.init()
|
827
872
|
}
|
@@ -1,151 +0,0 @@
|
|
1
|
-
function initializeCommentBarrage() {
|
2
|
-
window.commentBarrageInitialized = !0;
|
3
|
-
const e = {
|
4
|
-
maxBarrage: 1,
|
5
|
-
barrageTime: 8e3,
|
6
|
-
twikooUrl: GLOBAL_CONFIG.comment.url,
|
7
|
-
pageUrl: window.location.pathname,
|
8
|
-
accessToken: GLOBAL_CONFIG.comment.accessToken,
|
9
|
-
};
|
10
|
-
|
11
|
-
class CommentBarrage {
|
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
|
-
try {
|
27
|
-
const response = await fetch(this.config.twikooUrl, {
|
28
|
-
method: "POST",
|
29
|
-
headers: {
|
30
|
-
"Content-Type": "application/json"
|
31
|
-
},
|
32
|
-
body: JSON.stringify({
|
33
|
-
event: "COMMENT_GET",
|
34
|
-
accessToken: this.config.accessToken,
|
35
|
-
url: this.config.pageUrl
|
36
|
-
})
|
37
|
-
});
|
38
|
-
if (!response.ok) {
|
39
|
-
throw new Error("HTTP error! status: " + response.status);
|
40
|
-
}
|
41
|
-
const data = await response.json();
|
42
|
-
return data.data;
|
43
|
-
} catch (error) {
|
44
|
-
console.error("An error occurred while fetching comments: ", error);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
commentLinkFilter(comments) {
|
49
|
-
comments.sort((a, b) => a.created - b.created);
|
50
|
-
let filteredComments = [];
|
51
|
-
comments.forEach(comment => {
|
52
|
-
filteredComments.push(...this.getCommentReplies(comment));
|
53
|
-
});
|
54
|
-
return filteredComments;
|
55
|
-
}
|
56
|
-
|
57
|
-
getCommentReplies(comment) {
|
58
|
-
let comments = [comment];
|
59
|
-
if (comment.replies) {
|
60
|
-
comment.replies.forEach(reply => {
|
61
|
-
comments.push(...this.getCommentReplies(reply));
|
62
|
-
});
|
63
|
-
}
|
64
|
-
return comments;
|
65
|
-
}
|
66
|
-
|
67
|
-
processCommentContent(comment) {
|
68
|
-
const strippedContent = comment.replace(/<blockquote\b[^>]*>[\s\S]*?<\/blockquote>/gi, "");
|
69
|
-
const plainText = strippedContent.replace(/<[^>]*>/g, "").replace(/\n/g, " ");
|
70
|
-
return plainText.trim() !== "" ? `<p>${plainText}</p>` : "";
|
71
|
-
}
|
72
|
-
|
73
|
-
popCommentBarrage(comment) {
|
74
|
-
const commentContent = this.processCommentContent(comment.comment);
|
75
|
-
if (!commentContent.trim()) {
|
76
|
-
return false;
|
77
|
-
}
|
78
|
-
const commentBarrageItem = document.createElement("div");
|
79
|
-
commentBarrageItem.className = "comment-barrage-item";
|
80
|
-
commentBarrageItem.innerHTML = `
|
81
|
-
<div class="barrageHead">
|
82
|
-
<a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">${GLOBAL_CONFIG.lang.barrage.title}</a>
|
83
|
-
<div class="barrageNick">${comment.nick}</div>
|
84
|
-
<img class="barrageAvatar" src="${GLOBAL_CONFIG.comment.avatar}/avatar/${comment.mailMd5}"/>
|
85
|
-
<a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();"><i class="solitude st-close-fill"></i></a>
|
86
|
-
</div>
|
87
|
-
<a class="barrageContent" href="javascript:sco.scrollTo('${comment.id}');">${commentContent}</a>
|
88
|
-
`;
|
89
|
-
this.config.barrageTimer.push(commentBarrageItem);
|
90
|
-
this.config.dom.appendChild(commentBarrageItem);
|
91
|
-
return true;
|
92
|
-
}
|
93
|
-
|
94
|
-
removeCommentBarrage(commentBarrageItem) {
|
95
|
-
commentBarrageItem.className = "comment-barrage-item out";
|
96
|
-
setTimeout(() => {
|
97
|
-
this.config.dom.removeChild(commentBarrageItem);
|
98
|
-
}, 1000);
|
99
|
-
}
|
100
|
-
|
101
|
-
async initCommentBarrage() {
|
102
|
-
const commentBarrageSwitch = localStorage.getItem("commentBarrageSwitch");
|
103
|
-
if (commentBarrageSwitch != null) {
|
104
|
-
document.querySelector(".comment-barrage").style.display = "flex";
|
105
|
-
document.querySelector("#consoleCommentBarrage").classList.add("on");
|
106
|
-
} else {
|
107
|
-
document.querySelector(".comment-barrage").style.display = "none";
|
108
|
-
document.querySelector("#consoleCommentBarrage").classList.remove("on");
|
109
|
-
}
|
110
|
-
const comments = await this.fetchComments();
|
111
|
-
this.config.barrageList = this.commentLinkFilter(comments);
|
112
|
-
this.config.dom.innerHTML = "";
|
113
|
-
clearInterval(this.commentInterval);
|
114
|
-
this.commentInterval = null;
|
115
|
-
const t = () => {
|
116
|
-
if (this.config.barrageList.length && !this.hoverOnCommentBarrage) {
|
117
|
-
if (!this.popCommentBarrage(this.config.barrageList[this.config.barrageIndex])) {
|
118
|
-
this.config.barrageIndex += 1;
|
119
|
-
this.config.barrageIndex %= this.config.barrageList.length;
|
120
|
-
return t();
|
121
|
-
}
|
122
|
-
this.config.barrageIndex += 1;
|
123
|
-
this.config.barrageIndex %= this.config.barrageList.length;
|
124
|
-
}
|
125
|
-
if (this.config.barrageTimer.length > (this.config.barrageList.length > this.config.maxBarrage ? this.config.maxBarrage : this.config.barrageList.length) && !this.hoverOnCommentBarrage) {
|
126
|
-
this.removeCommentBarrage(this.config.barrageTimer.shift());
|
127
|
-
}
|
128
|
-
};
|
129
|
-
setTimeout(() => {
|
130
|
-
t();
|
131
|
-
if (this.commentInterval) {
|
132
|
-
clearInterval(this.commentInterval);
|
133
|
-
}
|
134
|
-
this.commentInterval = setInterval(t, this.config.barrageTime);
|
135
|
-
}, 3000);
|
136
|
-
}
|
137
|
-
|
138
|
-
init() {
|
139
|
-
this.initCommentBarrage();
|
140
|
-
const commentBarrage = document.querySelector(".comment-barrage");
|
141
|
-
commentBarrage.addEventListener('mouseover', () => {
|
142
|
-
this.hoverOnCommentBarrage = true;
|
143
|
-
});
|
144
|
-
commentBarrage.addEventListener('mouseout', () => {
|
145
|
-
this.hoverOnCommentBarrage = false;
|
146
|
-
});
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
new CommentBarrage(e);
|
151
|
-
}
|
@@ -1,156 +0,0 @@
|
|
1
|
-
function initializeCommentBarrage() {
|
2
|
-
window.commentBarrageInitialized = !0;
|
3
|
-
let config = {
|
4
|
-
maxBarrage: 1,
|
5
|
-
barrageTime: 8e3,
|
6
|
-
valineUrl: 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.valineUrl}/1.1/classes/Comment`);
|
27
|
-
const params = {
|
28
|
-
url: this.config.pageUrl,
|
29
|
-
order: '-createdAt'
|
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
|
-
"X-LC-Id": GLOBAL_CONFIG.comment.appId,
|
41
|
-
"X-LC-Key": GLOBAL_CONFIG.comment.appKey,
|
42
|
-
"Content-Type": "application/json"
|
43
|
-
},
|
44
|
-
});
|
45
|
-
|
46
|
-
if (!response.ok) {
|
47
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
48
|
-
}
|
49
|
-
|
50
|
-
const data = await response.json();
|
51
|
-
return data.results.filter(item => item.url === this.config.pageUrl)
|
52
|
-
} catch (error) {
|
53
|
-
console.error("An error occurred while fetching comments: ", error);
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
commentLinkFilter(comments) {
|
58
|
-
return comments.flatMap(comment => this.getCommentReplies(comment));
|
59
|
-
}
|
60
|
-
|
61
|
-
getCommentReplies(comment) {
|
62
|
-
window.comment = comment
|
63
|
-
if (!comment.replies) {
|
64
|
-
return [comment];
|
65
|
-
}
|
66
|
-
return [comment, ...comment.replies.flatMap(reply => this.getCommentReplies(reply))];
|
67
|
-
}
|
68
|
-
|
69
|
-
processCommentContent(comment) {
|
70
|
-
const processed = comment.replace(/```[\s\S]*?```|<blockquote\b[^>]*>[\s\S]*?<\/blockquote>|<[^>]*>|\n|`([^`]{1,9})`:/g, "").trim();
|
71
|
-
return processed ? `<p>${processed}</p>` : "";
|
72
|
-
}
|
73
|
-
|
74
|
-
createCommentBarrage(comment) {
|
75
|
-
const content = this.processCommentContent(comment.comment).trim();
|
76
|
-
if (!content) {
|
77
|
-
return false;
|
78
|
-
}
|
79
|
-
|
80
|
-
const element = document.createElement("div");
|
81
|
-
element.classList.add("comment-barrage-item");
|
82
|
-
element.innerHTML = `
|
83
|
-
<div class="barrageHead">
|
84
|
-
<a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">${GLOBAL_CONFIG.lang.barrage.title}</a>
|
85
|
-
<div class="barrageNick">${comment.nick}</div>
|
86
|
-
<img class="barrageAvatar" src="${GLOBAL_CONFIG.comment.avatar}/avatar/${md5(comment.mail.toLowerCase())}"/>
|
87
|
-
<a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();">
|
88
|
-
<i class="solitude st-close-fill"></i>
|
89
|
-
</a>
|
90
|
-
</div>
|
91
|
-
<a class="barrageContent" href="javascript:sco.scrollTo('${comment.objectId}');">${comment.comment}</a>
|
92
|
-
`;
|
93
|
-
|
94
|
-
this.config.dom.appendChild(element);
|
95
|
-
this.config.barrageTimer.push(element);
|
96
|
-
|
97
|
-
return true;
|
98
|
-
}
|
99
|
-
|
100
|
-
removeCommentBarrage(element) {
|
101
|
-
element.className = "comment-barrage-item out";
|
102
|
-
setTimeout(() => {
|
103
|
-
this.config.dom.removeChild(element);
|
104
|
-
}, 1000);
|
105
|
-
}
|
106
|
-
|
107
|
-
async initCommentBarrage() {
|
108
|
-
const commentBarrage = document.querySelector(".comment-barrage");
|
109
|
-
const menuCommentBarrageText = document.querySelector(".menu-commentBarrage-text");
|
110
|
-
const consoleCommentBarrage = document.querySelector("#consoleCommentBarrage");
|
111
|
-
|
112
|
-
if (localStorage.getItem("commentBarrageSwitch") != null) {
|
113
|
-
commentBarrage.style.display = "flex";
|
114
|
-
consoleCommentBarrage.classList.add("on");
|
115
|
-
} else {
|
116
|
-
commentBarrage.style.display = "none";
|
117
|
-
consoleCommentBarrage.classList.remove("on");
|
118
|
-
}
|
119
|
-
|
120
|
-
const comments = await this.fetchComments();
|
121
|
-
this.config.barrageList = this.commentLinkFilter(comments);
|
122
|
-
this.config.dom.innerHTML = "";
|
123
|
-
clearInterval(this.commentInterval);
|
124
|
-
this.commentInterval = null;
|
125
|
-
|
126
|
-
const createOrRemoveBarrage = () => {
|
127
|
-
if (this.config.barrageList.length && !this.hoverOnCommentBarrage) {
|
128
|
-
if (!this.createCommentBarrage(this.config.barrageList[this.config.barrageIndex])) {
|
129
|
-
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
130
|
-
return createOrRemoveBarrage();
|
131
|
-
}
|
132
|
-
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
133
|
-
}
|
134
|
-
if (this.config.barrageTimer.length > (this.config.barrageList.length > this.config.maxBarrage ? this.config.maxBarrage : this.config.barrageList.length) && !this.hoverOnCommentBarrage) {
|
135
|
-
this.removeCommentBarrage(this.config.barrageTimer.shift());
|
136
|
-
}
|
137
|
-
};
|
138
|
-
|
139
|
-
setTimeout(() => {
|
140
|
-
createOrRemoveBarrage();
|
141
|
-
if (this.commentInterval) {
|
142
|
-
clearInterval(this.commentInterval);
|
143
|
-
}
|
144
|
-
this.commentInterval = setInterval(createOrRemoveBarrage, this.config.barrageTime);
|
145
|
-
}, 3000);
|
146
|
-
}
|
147
|
-
|
148
|
-
async init() {
|
149
|
-
await this.initCommentBarrage();
|
150
|
-
const commentBarrage = document.querySelector(".comment-barrage");
|
151
|
-
commentBarrage.addEventListener('mouseover', () => this.hoverOnCommentBarrage = true);
|
152
|
-
commentBarrage.addEventListener('mouseout', () => this.hoverOnCommentBarrage = false);
|
153
|
-
}
|
154
|
-
}
|
155
|
-
(config)
|
156
|
-
}
|