Skip to content

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

Closed
echs-top opened this issue Apr 3, 2024 · 5 comments
Closed

请求增加 整个站点的总评论数调用 #811

echs-top opened this issue Apr 3, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@echs-top
Copy link

echs-top commented Apr 3, 2024

如标题

@dianso
Copy link

dianso commented Apr 4, 2024

我也需要这个功能。

不过我是问了gpt,写了个脚本

sqlite3 /artalk/artalk.db "SELECT COUNT(*) FROM comments;"

然后调用这个数字

@qwqcode qwqcode added the enhancement New feature or request label Apr 25, 2024
@qwqcode
Copy link
Member

qwqcode commented May 2, 2024

你好,这个功能已经存在了,GET 请求 https://artalk.xxx.com/api/v2/stats/site_comment?site_name=站点名 可以得到 {"data":957}

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

@echs-top
Copy link
Author

没看懂如何引用,我自己只是兴趣,有没有示例

@echs-top
Copy link
Author

Screenshot_2024-05-21-22-55-13-937_bin mt plus
比如图中的部分

@qwqcode
Copy link
Member

qwqcode commented May 26, 2024

From ChatGPT:

要将数据输出到 HTML 中,你可以使用 JavaScript 来操作 DOM,并将获取的数据插入到 HTML 元素中。以下是一个简单的例子,假设你有一个 <div> 元素用于显示数据:

<!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>

在这个例子中,我们创建了一个 <div> 元素并为其设置了一个唯一的 ID("dataContainer")。在 JavaScript 部分,我们通过 document.getElementById('dataContainer') 获取了这个元素的引用,然后将获取的数据插入到这个元素的 innerHTML 中。这里使用了 JSON.stringify() 将 JavaScript 对象转换为字符串,以便直接显示在 HTML 中。

你可以根据你的需求修改这个例子,比如更改数据展示的方式、样式等。

@qwqcode qwqcode closed this as completed May 26, 2024
@ArtalkJS ArtalkJS locked and limited conversation to collaborators May 26, 2024
@qwqcode qwqcode converted this issue into discussion #885 May 26, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants