-
如标题 |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
我也需要这个功能。 不过我是问了gpt,写了个脚本 sqlite3 /artalk/artalk.db "SELECT COUNT(*) FROM comments;" 然后调用这个数字 |
Beta Was this translation helpful? Give feedback.
-
你好,这个功能已经存在了,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 |
Beta Was this translation helpful? Give feedback.
-
没看懂如何引用,我自己只是兴趣,有没有示例 |
Beta Was this translation helpful? Give feedback.
-
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> 在这个例子中,我们创建了一个 你可以根据你的需求修改这个例子,比如更改数据展示的方式、样式等。 |
Beta Was this translation helpful? Give feedback.
From ChatGPT:
要将数据输出到 HTML 中,你可以使用 JavaScript 来操作 DOM,并将获取的数据插入到 HTML 元素中。以下是一个简单的例子,假设你有一个
<div>
元素用于显示数据: