1 Star 0 Fork 0

恐咖兵糖/www.ftls.xyz

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
pocketbase2.html 2.48 KB
Copy Edit Raw Blame History
恐咖兵糖 authored 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

Search