hexo-theme-stellar/source/js/services/waline_latest_comment.js

32 lines
1.4 KiB
JavaScript
Raw Normal View History

utils.jq(() => {
$(function () {
const els = document.getElementsByClassName('ds-waline');
for (var i = 0; i < els.length; i++) {
const el = els[i];
const limit = parseInt(el.getAttribute('limit')) || 10;
const apiBase = el.getAttribute('api');
if (apiBase == null) {
continue;
}
const api = apiBase + '/comment?type=recent&count=' + limit;
const default_avatar = def.avatar;
utils.request(el, api, function(data) {
data.forEach((item, i) => {
var cell = '<div class="timenode" index="' + i + '">';
cell += '<div class="header">';
cell += '<div class="user-info">';
2024-10-25 21:20:18 +08:00
cell += '<img src="' + (item.avatar || default_avatar) + '" onerror="javascript:this.src=\'' + default_avatar + '\';">';
cell += '<span>' + item.nick + '</span>';
cell += '</div>';
cell += '<span>' + new Date(item.time).toLocaleString() + '</span>';
cell += '</div>';
cell += '<a class="body" href="' + item.url + '#' + item.objectId + '" target="_blank" rel="external nofollow noopener noreferrer">';
2024-10-25 21:20:18 +08:00
cell += item.comment.replace(/<a\b[^>]*>(.*?)<\/a>/g, '$1');
cell += '</a>';
cell += '</div>';
$(el).append(cell);
});
});
}
});
2024-10-25 21:20:18 +08:00
});