17.10
This commit is contained in:
1 parent
d1584c1332
commit
dfaa1c3581
20 files changed
+196
-253
No files matched your search
@@ -93,6 +93,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/about\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -178,6 +178,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/archives\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
<link rel="stylesheet" href="/css/uikit.min.css">
|
||||
<link rel="stylesheet" href="/css/nprogress.min.css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/@waline/client@v3/dist/waline.css" />
|
||||
<link rel="stylesheet" href="https://usj.cc/usr/themes/Ying/css/barrager.css">
|
||||
<script src="/js/jquery.min.js"></script>
|
||||
<script src="https://usj.cc/usr/themes/Ying/js/jquery.barrager.js"></script>
|
||||
<script src="/js/jquery.scrollUp.min.js"></script>
|
||||
<script src="/js/pjax.js"></script>
|
||||
<script>console.log("\n %c Amigo Theme %c https://usj.cc \n", "color: #fadfa3; background: #030307; padding:3px; font-size:12px;", "color: #ffffff;background: #16171a; padding: 3px; font-size: 12px;");</script>
|
||||
@@ -82,12 +84,7 @@
|
||||
© 2019 - 2024
|
||||
<br>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank"><span style="color:#999999;">鄂ICP备2022015735号-1</span></a>
|
||||
<br>
|
||||
本站由<a href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" target="blank" title="又拍云"
|
||||
style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
|
||||
<span style="color: var(--contentColor);font-weight: 700;">又拍云CDN</span>
|
||||
</a>提供CDN加速服务
|
||||
<br>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
@@ -100,6 +97,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/categories\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -46,3 +46,43 @@ lazyLoadInit({
|
||||
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
@@ -183,5 +183,7 @@
|
||||
});
|
||||
});
|
||||
// pjax完成后加载 waline
|
||||
initWaline();
|
||||
if (currentPath.includes("/post/") || currentPath.includes("/says/")) {
|
||||
initWaline();
|
||||
}
|
||||
});
|
||||
@@ -266,6 +266,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/links\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -88,59 +88,23 @@
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
|
||||
var currentPath = "\/post\/demo01\/";
|
||||
|
||||
|
||||
$.ajaxSettings.async = true;
|
||||
$.getJSON('https://waline.usj.cc/api/comment?path=' + encodeURIComponent(currentPath), function(response) {
|
||||
var data = response.data.data;
|
||||
console.log(data);
|
||||
|
||||
var looper_time = 3 * 1000;
|
||||
var items = data;
|
||||
|
||||
var total = items.length;
|
||||
|
||||
var run_once = true;
|
||||
|
||||
var index = 0;
|
||||
|
||||
barrager();
|
||||
|
||||
function barrager() {
|
||||
if (run_once) {
|
||||
|
||||
looper = setInterval(barrager, looper_time);
|
||||
run_once = false;
|
||||
}
|
||||
|
||||
|
||||
var item = {
|
||||
img: items[index].avatar || 'static/default-avatar.png',
|
||||
info: items[index].orig || 'No comment',
|
||||
href: items[index].link || '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
};
|
||||
|
||||
|
||||
$('body').barrager(item);
|
||||
|
||||
index++;
|
||||
|
||||
if (index == total) {
|
||||
clearInterval(looper);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fetchCommentsAndCreateBarrager(currentPath, {
|
||||
looper_time: 3000,
|
||||
defaultAvatar: 'static/default-avatar.png',
|
||||
defaultInfo: 'No comment',
|
||||
defaultLink: '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -163,6 +127,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/post\/demo01\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -90,59 +90,23 @@
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
|
||||
var currentPath = "\/post\/demo03\/";
|
||||
|
||||
|
||||
$.ajaxSettings.async = true;
|
||||
$.getJSON('https://waline.usj.cc/api/comment?path=' + encodeURIComponent(currentPath), function(response) {
|
||||
var data = response.data.data;
|
||||
console.log(data);
|
||||
|
||||
var looper_time = 3 * 1000;
|
||||
var items = data;
|
||||
|
||||
var total = items.length;
|
||||
|
||||
var run_once = true;
|
||||
|
||||
var index = 0;
|
||||
|
||||
barrager();
|
||||
|
||||
function barrager() {
|
||||
if (run_once) {
|
||||
|
||||
looper = setInterval(barrager, looper_time);
|
||||
run_once = false;
|
||||
}
|
||||
|
||||
|
||||
var item = {
|
||||
img: items[index].avatar || 'static/default-avatar.png',
|
||||
info: items[index].orig || 'No comment',
|
||||
href: items[index].link || '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
};
|
||||
|
||||
|
||||
$('body').barrager(item);
|
||||
|
||||
index++;
|
||||
|
||||
if (index == total) {
|
||||
clearInterval(looper);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fetchCommentsAndCreateBarrager(currentPath, {
|
||||
looper_time: 3000,
|
||||
defaultAvatar: 'static/default-avatar.png',
|
||||
defaultInfo: 'No comment',
|
||||
defaultLink: '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -165,6 +129,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/post\/demo03\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
<link rel="stylesheet" href="/css/uikit.min.css">
|
||||
<link rel="stylesheet" href="/css/nprogress.min.css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/@waline/client@v3/dist/waline.css" />
|
||||
<link rel="stylesheet" href="https://usj.cc/usr/themes/Ying/css/barrager.css">
|
||||
<script src="/js/jquery.min.js"></script>
|
||||
<script src="https://usj.cc/usr/themes/Ying/js/jquery.barrager.js"></script>
|
||||
<script src="/js/jquery.scrollUp.min.js"></script>
|
||||
<script src="/js/pjax.js"></script>
|
||||
<script>console.log("\n %c Amigo Theme %c https://usj.cc \n", "color: #fadfa3; background: #030307; padding:3px; font-size:12px;", "color: #ffffff;background: #16171a; padding: 3px; font-size: 12px;");</script>
|
||||
@@ -61,7 +63,7 @@
|
||||
|
||||
|
||||
<div id="pjax-container">
|
||||
<article>
|
||||
<article style="margin-bottom: 3.5em;">
|
||||
<h1 class="post-title" itemprop="name headline">Helloworld</h1>
|
||||
<div class="meta">
|
||||
作者: 小赵同学 浏览: 字数: 3 分类:
|
||||
@@ -78,10 +80,30 @@
|
||||
</nav>
|
||||
</div>
|
||||
</article>
|
||||
<hr class="uk-divider-icon">
|
||||
<div id="comments" class="comments-area">
|
||||
|
||||
<div id="waline"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
|
||||
var currentPath = "\/post\/helloworld\/";
|
||||
|
||||
|
||||
fetchCommentsAndCreateBarrager(currentPath, {
|
||||
looper_time: 3000,
|
||||
defaultAvatar: 'static/default-avatar.png',
|
||||
defaultInfo: 'No comment',
|
||||
defaultLink: '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -91,12 +113,7 @@
|
||||
© 2019 - 2024
|
||||
<br>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank"><span style="color:#999999;">鄂ICP备2022015735号-1</span></a>
|
||||
<br>
|
||||
本站由<a href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" target="blank" title="又拍云"
|
||||
style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
|
||||
<span style="color: var(--contentColor);font-weight: 700;">又拍云CDN</span>
|
||||
</a>提供CDN加速服务
|
||||
<br>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
@@ -109,6 +126,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/post\/helloworld\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
<link rel="stylesheet" href="/css/uikit.min.css">
|
||||
<link rel="stylesheet" href="/css/nprogress.min.css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/@waline/client@v3/dist/waline.css" />
|
||||
<link rel="stylesheet" href="https://usj.cc/usr/themes/Ying/css/barrager.css">
|
||||
<script src="/js/jquery.min.js"></script>
|
||||
<script src="https://usj.cc/usr/themes/Ying/js/jquery.barrager.js"></script>
|
||||
<script src="/js/jquery.scrollUp.min.js"></script>
|
||||
<script src="/js/pjax.js"></script>
|
||||
<script>console.log("\n %c Amigo Theme %c https://usj.cc \n", "color: #fadfa3; background: #030307; padding:3px; font-size:12px;", "color: #ffffff;background: #16171a; padding: 3px; font-size: 12px;");</script>
|
||||
@@ -107,12 +109,7 @@
|
||||
© 2019 - 2024
|
||||
<br>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank"><span style="color:#999999;">鄂ICP备2022015735号-1</span></a>
|
||||
<br>
|
||||
本站由<a href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" target="blank" title="又拍云"
|
||||
style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
|
||||
<span style="color: var(--contentColor);font-weight: 700;">又拍云CDN</span>
|
||||
</a>提供CDN加速服务
|
||||
<br>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
@@ -125,6 +122,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/post\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -87,59 +87,23 @@
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
|
||||
var currentPath = "\/post\/my-first-post\/";
|
||||
|
||||
|
||||
$.ajaxSettings.async = true;
|
||||
$.getJSON('https://waline.usj.cc/api/comment?path=' + encodeURIComponent(currentPath), function(response) {
|
||||
var data = response.data.data;
|
||||
console.log(data);
|
||||
|
||||
var looper_time = 3 * 1000;
|
||||
var items = data;
|
||||
|
||||
var total = items.length;
|
||||
|
||||
var run_once = true;
|
||||
|
||||
var index = 0;
|
||||
|
||||
barrager();
|
||||
|
||||
function barrager() {
|
||||
if (run_once) {
|
||||
|
||||
looper = setInterval(barrager, looper_time);
|
||||
run_once = false;
|
||||
}
|
||||
|
||||
|
||||
var item = {
|
||||
img: items[index].avatar || 'static/default-avatar.png',
|
||||
info: items[index].orig || 'No comment',
|
||||
href: items[index].link || '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
};
|
||||
|
||||
|
||||
$('body').barrager(item);
|
||||
|
||||
index++;
|
||||
|
||||
if (index == total) {
|
||||
clearInterval(looper);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fetchCommentsAndCreateBarrager(currentPath, {
|
||||
looper_time: 3000,
|
||||
defaultAvatar: 'static/default-avatar.png',
|
||||
defaultInfo: 'No comment',
|
||||
defaultLink: '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -162,6 +126,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/post\/my-first-post\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -87,59 +87,23 @@
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
|
||||
var currentPath = "\/post\/my-second-post\/";
|
||||
|
||||
|
||||
$.ajaxSettings.async = true;
|
||||
$.getJSON('https://waline.usj.cc/api/comment?path=' + encodeURIComponent(currentPath), function(response) {
|
||||
var data = response.data.data;
|
||||
console.log(data);
|
||||
|
||||
var looper_time = 3 * 1000;
|
||||
var items = data;
|
||||
|
||||
var total = items.length;
|
||||
|
||||
var run_once = true;
|
||||
|
||||
var index = 0;
|
||||
|
||||
barrager();
|
||||
|
||||
function barrager() {
|
||||
if (run_once) {
|
||||
|
||||
looper = setInterval(barrager, looper_time);
|
||||
run_once = false;
|
||||
}
|
||||
|
||||
|
||||
var item = {
|
||||
img: items[index].avatar || 'static/default-avatar.png',
|
||||
info: items[index].orig || 'No comment',
|
||||
href: items[index].link || '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
};
|
||||
|
||||
|
||||
$('body').barrager(item);
|
||||
|
||||
index++;
|
||||
|
||||
if (index == total) {
|
||||
clearInterval(looper);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fetchCommentsAndCreateBarrager(currentPath, {
|
||||
looper_time: 3000,
|
||||
defaultAvatar: 'static/default-avatar.png',
|
||||
defaultInfo: 'No comment',
|
||||
defaultLink: '#',
|
||||
close: true,
|
||||
speed: 6,
|
||||
color: '#fff',
|
||||
old_ie_color: '#000000'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -162,6 +126,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/post\/my-second-post\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -76,6 +76,13 @@
|
||||
- 图标:https://usj.cc/favicon.ico
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="comments" class="comments-area">
|
||||
|
||||
<div id="waline"></div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -98,6 +105,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/says\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "\/tags\/";</script>
|
||||
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -9,5 +9,12 @@
|
||||
- 图标:https://usj.cc/favicon.ico
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="comments" class="comments-area">
|
||||
<!-- 评论区内容 -->
|
||||
<div id="waline"></div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
{{ end }}
|
||||
@@ -22,60 +22,24 @@
|
||||
<!-- 评论区内容 -->
|
||||
<div id="waline"></div>
|
||||
</div>
|
||||
|
||||
{{/* 文章页面评论弹幕 */}}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
// 获取当前页面的路径
|
||||
var currentPath = "{{ .RelPermalink }}";
|
||||
|
||||
// 动态获取评论并发布弹幕
|
||||
$.ajaxSettings.async = true;
|
||||
$.getJSON('https://waline.usj.cc/api/comment?path=' + encodeURIComponent(currentPath), function(response) {
|
||||
var data = response.data.data;
|
||||
console.log(data);
|
||||
// 每条弹幕发送间隔
|
||||
var looper_time = 3 * 1000;
|
||||
var items = data;
|
||||
// 弹幕总数
|
||||
var total = items.length;
|
||||
// 是否首次执行
|
||||
var run_once = true;
|
||||
// 弹幕索引
|
||||
var index = 0;
|
||||
// 先执行一次
|
||||
barrager();
|
||||
|
||||
function barrager() {
|
||||
if (run_once) {
|
||||
// 如果是首次执行, 则设置一个定时器, 并且把首次执行置为 false
|
||||
looper = setInterval(barrager, looper_time);
|
||||
run_once = false;
|
||||
}
|
||||
|
||||
// 转换数据为弹幕所需的格式
|
||||
var item = {
|
||||
img: items[index].avatar || 'static/default-avatar.png', // 头像
|
||||
info: items[index].orig || 'No comment', // 评论内容
|
||||
href: items[index].link || '#', // 用户链接
|
||||
close: true, // 显示关闭按钮
|
||||
speed: 6, // 延迟,单位秒,默认6
|
||||
color: '#fff', // 颜色,默认白色
|
||||
old_ie_color: '#000000' // ie低版兼容色,不能与网页背景相同,默认黑色
|
||||
};
|
||||
|
||||
// 发布一个弹幕
|
||||
$('body').barrager(item);
|
||||
// 索引自增
|
||||
index++;
|
||||
// 所有弹幕发布完毕,清除计时器
|
||||
if (index == total) {
|
||||
clearInterval(looper);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 调用封装的函数
|
||||
fetchCommentsAndCreateBarrager(currentPath, {
|
||||
looper_time: 3000, // 每条弹幕的发送间隔,单位毫秒
|
||||
defaultAvatar: 'static/default-avatar.png', // 默认头像
|
||||
defaultInfo: 'No comment', // 默认评论内容
|
||||
defaultLink: '#', // 默认用户链接
|
||||
close: true, // 显示关闭按钮
|
||||
speed: 6, // 弹幕速度,单位秒
|
||||
color: '#fff', // 弹幕颜色
|
||||
old_ie_color: '#000000' // IE低版兼容色
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
{{ end }}
|
||||
@@ -21,6 +21,7 @@
|
||||
<script src="/js/main.js"></script>
|
||||
<script src="/js/mypjax.js"></script>
|
||||
<script src="/js/nprogress.js"></script>
|
||||
<script>var currentPath = "{{ .RelPermalink }}";</script>
|
||||
<!-- 加载 Waline 和 PJAX -->
|
||||
<script type="module">
|
||||
import { init as walineInit } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
|
||||
|
||||
@@ -46,3 +46,43 @@ lazyLoadInit({
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -183,5 +183,7 @@
|
||||
});
|
||||
});
|
||||
// pjax完成后加载 waline
|
||||
initWaline();
|
||||
if (currentPath.includes("/post/") || currentPath.includes("/says/")) {
|
||||
initWaline();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user