// 判断是否为移动端 function isMobile() { if (window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) { return true; // 移动端 } else { return false; // PC端 } } // 文章图片灯箱 window.ViewImage && ViewImage.init('.post-content img'); // 激活返回顶部插件 $(function () { $.scrollUp({ animation: 'fade', scrollImg: true }); }); // loader定时器 $(document).ready(function () { setTimeout(function () { $("#loader").addClass("hide"); }, 30000); }); // 点击进入按钮 $("#closeloader").click(function () { $("#loader").addClass("hide"); }); // nav栏样式调整 $('#libabys').first().attr("style", "margin-left: -5px"); $('#libabys').eq(1).attr("style", "margin-left: -5px"); // 友链列表版样式调整 $('.itp-index:odd').attr("style", "float: right;width:48%;"); //文章图片懒加载 lazyLoadInit({ coverColor: "white", coverDiv: "
优世界·一个记录生活点滴的小站
", offsetBottom: 0, offsetTopm: 0, showTime: 1100 }); async function fetchCommentsAndCreateBarrager(path, options) { try { const response = await fetch('https://waline.usj.cc/api/comment?path=' + encodeURIComponent(path)); const data = await response.json(); if (!data.data || !data.data.data) { console.error('评论数据获取失败'); return; } const commentsData = data.data.data; const looperTime = options.looper_time || 3000; const flattenedComments = flattenComments(commentsData); const totalComments = flattenedComments.length; let currentIndex = 0; // 初始化弹幕插件 let barrage = new Barrage.default({ el: 'body', backColor:"#000000b5", fontSize:"14px", isLeft:true, speed:0, height:"35px" }); if (totalComments !== 0) { createBarrager(); } function createBarrager() { const currentComment = flattenedComments[currentIndex]; const barragerItem = { headImg: currentComment.avatar + "?s=24" || options.defaultAvatar, content: stripHTML(currentComment.orig) || options.defaultInfo, href: currentComment.link || options.defaultLink, speed: options.speed || 10 }; console.log(barragerItem.content); // 发送弹幕 barrage.start(barragerItem.content, { speed: barragerItem.speed, headImg: barragerItem.headImg, speed:25 }); currentIndex++; if (currentIndex < totalComments) { setTimeout(createBarrager, looperTime); } } function stripHTML(html) { return html.replace(/<\/?[^>]+(>|$)/g, ""); } function flattenComments(comments) { let result = []; comments.forEach(function(comment) { result.push(comment); if (comment.children && comment.children.length > 0) { result = result.concat(flattenComments(comment.children)); } }); return result; } } catch (error) { console.error('无法获取评论数据', error); } }