]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
content = content.replace(/.*?<\/pre>/gi, '[代码]') // replace code
content = content.replace(/<[^>]+>/g, "") // remove html tag
if (content.length > 150) {
content = content.substring(0, 150) + '...'
}
return content
}
function popCommentBarrage(data) {
let isTwikoo = commentBarrageConfig.use == 'Twikoo'
let isArtalk = commentBarrageConfig.use == 'Artalk';
let isWaline = commentBarrageConfig.use == 'Waline';
let nick = data.nick;
let avatar = isTwikoo ? `https://cravatar.cn/avatar/${data.mailMd5}` :
isArtalk ? `https://cravatar.cn/avatar/${data.email_encrypted}?d=mp&s=240` :
isWaline ? data.avatar : 'https://cravatar.cn/avatar/';
let barrageBlogger = isTwikoo ? data.mailMd5 === commentBarrageConfig.mailMd5 :
isArtalk ? data.email_encrypted === commentBarrageConfig.mailMd5 :
isWaline ? data.type === 'administrator' : false;
let id = isTwikoo ? data.id :
isArtalk ? 'atk-comment-' + data.id :
isWaline ? data.objectId : 'post-comment';
let comment = isTwikoo ? data.comment :
isArtalk ? data.content_marked :
isWaline ? data.comment : '';
let badge_name = isArtalk ? data.badge_name : '博主'
let badgeName = !barrageBlogger ? "热评" : badge_name != '' ? badge_name : "博主"
let barrage = document.createElement('div');
let width = commentBarrageConfig.dom.clientWidth;
let height = commentBarrageConfig.dom.clientHeight;
barrage.className = 'comment-barrage-item'
barrage.innerHTML = `
${changeContents(comment)}
`
// 获取hao标签内的所有pre元素
let haoPres = barrage.querySelectorAll(".barrageContent pre");
// 遍历每个pre元素,将其替换为"【代码】"
haoPres.forEach((pre) => {
let codePlaceholder = document.createElement("span");
codePlaceholder.innerText = "【代码】";
pre.parentNode.replaceChild(codePlaceholder, pre);
});
// 获取hao标签内的所有图片元素
let haoImages = barrage.querySelectorAll(".barrageContent img");
// 遍历每个图片元素,将其替换为"【图片】",但排除带有class=tk-owo-emotion的图片
haoImages.forEach((image) => {
if (!image.classList.contains("tk-owo-emotion")) {
image.style.display = "none"; // 隐藏图片
let placeholder = document.createElement("span");
placeholder.innerText = "【图片】";
image.parentNode.replaceChild(placeholder, image);
}
});
commentBarrageConfig.barrageTimer.push(barrage);
commentBarrageConfig.dom.append(barrage);
}
function removeCommentBarrage(barrage) {
barrage.className = 'comment-barrage-item out';
setTimeout(() => {
commentBarrageConfig.dom.removeChild(barrage);
}, 1000)
}
initCommentBarrage();
if (localStorage.getItem('commentBarrageSwitch') !== 'false') {
$(".comment-barrage").show();
$(".menu-commentBarrage-text").text("关闭热评");
document.querySelector("#consoleCommentBarrage").classList.add("on");
} else {
$(".comment-barrage").hide();
$(".menu-commentBarrage-text").text("显示热评");
document.querySelector("#consoleCommentBarrage").classList.remove("on");
}
document.addEventListener('pjax:send', function() {
clearInterval(commentInterval);
});
}