Update talks.html

This commit is contained in:
浪子 2024-06-21 09:27:47 +08:00
parent f0a338e584
commit 3a5c67281d
1 changed files with 4 additions and 75 deletions

View File

@ -1,80 +1,9 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script> <script src="https://blogcdn.loliko.cn/memos/top/moment.min.js"></script>
<script src="https://momentjs.cn/downloads/moment-with-locales.js"></script> <script src="https://blogcdn.loliko.cn/memos/top/moment-with-locales.js"></script>
<article class="post--item post--item__status" itemtype="http://schema.org/Article" itemscope="itemscope"> <article class="post--item post--item__status" itemtype="http://schema.org/Article" itemscope="itemscope">
<div class="content"> <div class="content"><div id="bber-talk"></div></div>
<div id="bber-talk"></div>
</div>
</article> </article>
<script> <script src="https://blogcdn.loliko.cn/memos/top/memos.js"></script>
document.addEventListener("DOMContentLoaded", function() {
var bbDom = document.querySelector('#bber-talk');
if (bbDom) {
memoTalks();
moment.locale('zh-CN');
}
function memoTalks() {
var bbUrl = "https://memos.ee/api/v1/memos?filter=visibilities==['PUBLIC']&pageSize=5";
fetch(bbUrl)
.then(res => res.json())
.then(resdata => {
var result = '', resultAll = "", data = resdata.memos;
for (var i = 0; i < data.length; i++) {
var bbTime = data[i].createTime;
var relativeTime = moment(bbTime).fromNow(); // 使用 moment.js 格式化相对时间
var bbCont = data[i].content;
var img = data[i].externalLink; // 获取 `externalLink` 字段
var memouid = data[i].uid;
// 标志变量,用于跟踪是否匹配到图片
var hasImage = false;
// 更智能的图片检测逻辑
var newbbCont = bbCont
.replace(/!\[.*?\]\((.*?)\)/g, function (match, url) {
hasImage = true; // 设置标志变量
return '<a href="' + url + '" target="_blank">🌅</a>'; // 返回带有图片图标的链接
})
.replace(/\[(.*?)\]\((.*?)\)/g, function (match, text, url) {
// 提取文件名部分
var filename = url.split('/').pop().split('?')[0].split('#')[0];
// 检查文件名是否包含常见图片格式
if (/\b(jpg|jpeg|png|gif|bmp)\b/i.test(filename)) {
hasImage = true; // 设置标志变量
return '<a href="' + url + '" target="_blank">🌅</a>'; // 返回带有图片图标的链接
}
return '<a href="' + url + '" target="_blank">' + text + ' 🔗</a>'; // 返回普通链接
});
// 如果 `img` 字段存在且包含图片格式,也添加带图片图标的链接
if (img && /\b(jpg|jpeg|png|gif|bmp)\b/i.test(img)) {
newbbCont += ' <a href="' + img + '" target="_blank">🌅</a>';
}
result += `<li class="item">💬 <a href="https://memos.ee/m/${memouid}" target="_blank"><span class="datetime">${relativeTime}</span>${newbbCont}</a></li>`;
}
var bbBefore = `<div class="talk-wrap"><ul class="talk-list">`;
var bbAfter = `</ul></div>`;
resultAll = bbBefore + result + bbAfter;
if (bbDom) {
bbDom.innerHTML = resultAll;
}
// 设置定时功能防止querySelectorAll错误
setInterval(function () {
var n = document.querySelector(".talk-list");
if (n) {
var e = n.querySelectorAll(".item");
for (var t = 0; t < e.length; t++) {
setTimeout(function () {
if (e[0]) n.appendChild(e[0]);
}, 1000);
}
}
}, 2000);
});
}
});
</script>
<style> <style>
.talk-list .item { .talk-list .item {
display: none; display: none;