This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请求增加 整个站点的总评论数调用 #811
Comments
我也需要这个功能。 不过我是问了gpt,写了个脚本 sqlite3 /artalk/artalk.db "SELECT COUNT(*) FROM comments;" 然后调用这个数字 |
你好,这个功能已经存在了,GET 请求 const siteName = '站点名'; // 替换为实际的站点名
const url = `https://artalk.xxx.com/api/v2/stats/site_comment?site_name=${encodeURIComponent(siteName)}`;
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(({ data }) => {
console.log(data); // 输出获取的数据
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
}); https://artalk.js.org/http-api.html#tag/Statistic/operation/GetStats |
没看懂如何引用,我自己只是兴趣,有没有示例 |
From ChatGPT: 要将数据输出到 HTML 中,你可以使用 JavaScript 来操作 DOM,并将获取的数据插入到 HTML 元素中。以下是一个简单的例子,假设你有一个 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>显示数据</title>
</head>
<body>
<div id="dataContainer"></div>
<script>
const siteName = '站点名'; // 替换为实际的站点名
const url = `https://artalk.xxx.com/api/v2/stats/site_comment?site_name=${encodeURIComponent(siteName)}`;
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(({ data }) => {
// 将数据插入到 HTML 元素中
const dataContainer = document.getElementById('dataContainer');
dataContainer.innerHTML = JSON.stringify(data); // 这里使用 JSON.stringify() 将数据转换为字符串输出
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
</script>
</body>
</html> 在这个例子中,我们创建了一个 你可以根据你的需求修改这个例子,比如更改数据展示的方式、样式等。 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
如标题
The text was updated successfully, but these errors were encountered: