1 Star 0 Fork 0

恐咖兵糖/www.ftls.xyz

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pocketbase2.html 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
恐咖兵糖 提交于 2024-04-18 22:29 +08:00 . pref: 增加注释 优化文件
<!-- 博客嵌入 pocketbase item -->
<div id="pocketbase">
<div id="tweetList"></div>
<a id="moreButton" href="#" onclick="showMore(); return false;">更多</a>
</div>
<script type="text/javascript" src="/js/time-fmt.min.js"></script>
<script type="text/javascript">
const tweetList = document.getElementById('tweetList');
const moreButton = document.getElementById('moreButton');
const apiUrl = "https://note.ftls.xyz/json/pb.json"; //"https://api.ftls.xyz/api/collections/whispers/records";
let currentPage = 1;
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function displayTweets(tweets) {
tweets.forEach(tweet => {
const blockquote = document.createElement('blockquote');
const createdAtDiv = document.createElement('div');
createdAtDiv.textContent = formatTime(tweet.createdAt); // moment.js 或者 相对时间 Lately.js 也可
const contentDiv = document.createElement('div');
contentDiv.innerHTML = escapeHtml(tweet.text).replace(/\!\[.*\]\((.+)\)/g, '<img src="$1" loading="lazy" />');
blockquote.appendChild(createdAtDiv);
blockquote.appendChild(contentDiv);
tweetList.appendChild(blockquote);
});
// window.Lately && Lately.init({ target: '.lately' }); // 相对时间 Lately.js 初始化
}
function fetchTweets(page) {
const params = new URLSearchParams({
sort: '-createdAt',
perPage: 5,
page: page
});
const url = `${apiUrl}?${params.toString()}`;
fetch(url)
.then(response => response.json())
.then(data => {
displayTweets(data.items);
if (data.page < data.totalPages) {
moreButton.style.display = 'block';
currentPage = data.page + 1;
} else {
moreButton.style.display = 'none';
}
});
}
function showMore() {
moreButton.style.display = 'none';
fetchTweets(currentPage);
}
// 页面加载时获取第一页推文
fetchTweets(currentPage);
</script>
<!-- 简易样式;如果 Hugo 主题有样式可能会被覆盖 -->
<!-- <style>
blockquote {
margin: 0;
}
blockquote p {
padding: 15px;
background: #eee;
border-radius: 5px;
}
</style> -->
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kkbt/www.ftls.xyz.git
git@gitee.com:kkbt/www.ftls.xyz.git
kkbt
www.ftls.xyz
www.ftls.xyz
master

搜索帮助