blog-186/themes/suka/layout/_plugin/comment/valine/main.ejs

67 lines
2.9 KiB
Plaintext

<div id="vcomments">Loading……
<a onclick="window.valinenow();">强制加载Waline</a>
<noscript>启动js来查看评论</noscript>
</div>
<!--<script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js"></script>-->
<script>
var GUEST_INFO = ['nick', 'mail', 'link'];
var guest_info = '<%= theme.comment.valine.guest_info %>'.split(',').filter(function (item) {
return GUEST_INFO.indexOf(item) > -1
});
var notify = '<%= theme.comment.valine_notify %>' === 'true';
var verify = '<%= theme.comment.valine_verify %>' === 'true';
function valinenow(){
var a = document.createElement("script"),d = document;
a.src = "https://cdn.jsdelivr.net/npm/@waline/client@0.14.8/dist/Waline.min.js";
(d.head || d.body).appendChild(a);
whenAvailable("Waline", function(){
const Valine = Waline;
new Valine({
el: '#vcomments',
notify: notify,
verify: verify,
serverURL: 'https://comment.186526.xyz',
avatarCDN: 'https://comment.186526.xyz/avatar/',
placeholder: "<%= theme.comment.valine.placeholder %>",
meta: guest_info,
pageSize: '<%= theme.comment.valine.pageSize %>',
avatar: '<%= theme.comment.valine.avatar %>',
lang: '<%= theme.comment.valine.lang %>',
guest_info: guest_info,
visitor: <%= theme.valine_counter.enable %>
});
})
};
function valinedo(){
var runningOnBrowser = typeof window !== "undefined";
var isBot = runningOnBrowser && !("onscroll" in window) || typeof navigator !== "undefined" && /(gle|ing|ro|msn)bot|crawl|spider|yand|duckgo/i.test(navigator.userAgent);
var supportsIntersectionObserver = runningOnBrowser && "IntersectionObserver" in window;
if (!isBot && supportsIntersectionObserver) {
var valine_observer = new IntersectionObserver(function (entries) {
if (entries[0].isIntersecting) {
valinenow();
valine_observer.disconnect();
}
}, { threshold: [0] });
valine_observer.observe(document.getElementById('vcomments'));
} else {
valinenow();
}
}
if(!window.whenAvailable){
window.whenAvailable = function(name, callback){
var interval = 100;
window.setTimeout(function () {
if (window[name]) {
callback(window[name]);
} else {
window.setTimeout(arguments.callee, interval);
}
}, interval);
}
}
document.dispatchEvent(new window.Event("LoadValine"));
valinedo();
</script>