2024-07-11 08:59:32 +08:00
|
|
|
// 判断是否为移动端
|
|
|
|
|
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('#writing_content img');
|
|
|
|
|
|
|
|
|
|
//memos图片灯箱
|
|
|
|
|
window.ViewImage && ViewImage.init('.text img , .memos-photo img , .gallery-thumbnail 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: "<div style='display: flex; justify-content: center; align-items: center; height: 200px;color: #000000;'><span>优世界·一个记录生活点滴的小站</span></div>",
|
|
|
|
|
offsetBottom: 0,
|
|
|
|
|
offsetTopm: 0,
|
|
|
|
|
showTime: 1100
|
2024-07-12 17:10:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 封装的函数:获取评论数据并发布弹幕
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|