This commit is contained in:
小赵同学 committed 2024-07-12 17:10:51 +08:00
1 parent d1584c1332
commit dfaa1c3581
20 files changed
+217 -274

No files matched your search

+41 -1
View File
@@ -45,4 +45,44 @@ lazyLoadInit({
offsetBottom: 0,
offsetTopm: 0,
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 total = items.length;
// 弹幕索引
var index = 0;
// 先执行一次
createBarrager();
function createBarrager() {
// 转换数据为弹幕所需的格式
var item = {
img: items[index].avatar || options.defaultAvatar || 'static/default-avatar.png', // 头像
info: items[index].orig || options.defaultInfo || 'No comment', // 评论内容
href: items[index].link || options.defaultLink || '#', // 用户链接
close: options.close || true, // 显示关闭按钮
speed: options.speed || 6, // 延迟,单位秒,默认6
color: options.color || '#fff', // 颜色,默认白色
old_ie_color: options.old_ie_color || '#000000' // ie低版兼容色,不能与网页背景相同,默认黑色
};
// 发布一个弹幕
$('body').barrager(item);
// 索引自增
index++;
// 所有弹幕发布完毕,清除计时器
if (index < total) {
setTimeout(createBarrager, looper_time);
}
}
});
}
+3 -1
View File
@@ -183,5 +183,7 @@
});
});
// pjax完成后加载 waline
initWaline();
if (currentPath.includes("/post/") || currentPath.includes("/says/")) {
initWaline();
}
});