2024.7.28 完工
This commit is contained in:
1 parent
ad1de354c2
commit
cfd81bccef
130 files changed
+419
-383
No files matched your search
@@ -44,29 +44,28 @@ lazyLoadInit({
|
||||
showTime: 1100
|
||||
});
|
||||
|
||||
// 封装的函数:获取评论数据并发布弹幕
|
||||
|
||||
function fetchCommentsAndCreateBarrager(path, options) {
|
||||
$.getJSON('https://waline.usj.cc/api/comment?path=' + encodeURIComponent(path), function(response) {
|
||||
var data = response.data.data;
|
||||
console.log(data);
|
||||
|
||||
// 每条弹幕发送间隔
|
||||
var looper_time = options.looper_time || 3000; // 默认间隔3秒
|
||||
var items = data;
|
||||
var items = flattenComments(data);
|
||||
// 弹幕总数
|
||||
var total = items.length;
|
||||
// 弹幕索引
|
||||
var index = 0;
|
||||
// 先执行一次
|
||||
if(total != 0){
|
||||
createBarrager()
|
||||
if (total != 0) {
|
||||
createBarrager();
|
||||
}
|
||||
|
||||
function createBarrager() {
|
||||
// 转换数据为弹幕所需的格式
|
||||
var item = {
|
||||
img: items[index].avatar || options.defaultAvatar || 'static/default-avatar.png', // 头像
|
||||
info: items[index].orig || options.defaultInfo || 'No comment', // 评论内容
|
||||
info: stripHTML(items[index].orig) || options.defaultInfo || 'No comment', // 过滤后的评论内容
|
||||
href: items[index].link || options.defaultLink || '#', // 用户链接
|
||||
close: options.close || true, // 显示关闭按钮
|
||||
speed: options.speed || 6, // 延迟,单位秒,默认6
|
||||
@@ -83,5 +82,22 @@ function fetchCommentsAndCreateBarrager(path, options) {
|
||||
setTimeout(createBarrager, looper_time);
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤HTML标签的函数
|
||||
function stripHTML(html) {
|
||||
return html.replace(/<\/?[^>]+(>|$)/g, "");
|
||||
}
|
||||
|
||||
// 展平评论和子评论
|
||||
function flattenComments(comments) {
|
||||
var result = [];
|
||||
comments.forEach(function(comment) {
|
||||
result.push(comment);
|
||||
if (comment.children && comment.children.length > 0) {
|
||||
result = result.concat(flattenComments(comment.children));
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user