1 Star 0 Fork 0

恐咖兵糖/www.ftls.xyz

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mastodon.html 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
恐咖兵糖 提交于 2024-04-18 22:29 +08:00 . pref: 增加注释 优化文件
<!-- 博客嵌入 Mastodon 嘟嘟 -->
<div id="toots"></div>
<button id="toots-moreButton" onclick="tootsShowMore()">更多</button>
<script>
let maxId = null; // 初始值为 null,表示第一页
const tootsDiv = document.getElementById('toots');
const tootsMoreButton = document.getElementById('toots-moreButton');
// 获取 Mastodon 用户公开Toots 限制条数 默认5 排除回复 toot
async function getPublicToots() {
const queryParams = maxId ? ("?limit={{ .Get 2 | default 5 }}&max_id=" + maxId) : "?limit={{ .Get 2 | default 5 }}";
const response = await fetch("{{ .Get 0 }}/api/v1/accounts/{{ .Get 1 }}/statuses" + queryParams + "&exclude_replies=true");
const toots = await response.json();
return toots;
}
// 将Toots显示在页面上
async function displayToots() {
try {
const toots = await getPublicToots();
if (toots && toots.length > 0) {
toots.forEach(toot => {
const tootDiv = document.createElement('div');
tootDiv.innerHTML = `<p>${toot.content}</p><hr>`;
tootsDiv.appendChild(tootDiv);
maxId = toot.id; // 更新最大 ID
});
tootsMoreButton.style.display = 'block';
} else {
tootsMoreButton.style.display = 'none';
}
} catch (error) {
console.error('获取Toots时出错:', error);
tootsMoreButton.style.display = 'none';
}
}
function tootsShowMore() {
displayToots();
}
displayToots();
// 页面加载时调用显示Toots函数
// window.onload = displayToots;
</script>
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

搜索帮助