GithubHelp home page GithubHelp logo

evannotfound / vercount Goto Github PK

View Code? Open in Web Editor NEW
62.0 2.0 0.0 268 KB

Busuanzi Compatible Website Counter Powered by Vercel + Redis

Home Page: https://vercount.one

CSS 47.98% HTML 40.52% JavaScript 2.98% TypeScript 8.51%
busuanzi counter hexo website-counter busuanzi-statistics statistics

vercount's Introduction

Vercount 网站计数器

Powered by: 🚀 NextJS + Redis ✨ + Vercel

不蒜子计数访问慢?总是 502?那就试试 Vercount 吧!完美不蒜子计数替代方案。

Vercount 是一个基于 NextJS + Redis 的网站计数器,它的特点是:

  • 速度快,服务器响应时间在 10ms 以内
  • 可选使用**加速版本(国内访问优化),或者使用 Vercel 全球 CDN,保证 99.99% 可用性
  • 使用 POST 请求进行统计,不再使用不蒜子的过时 Referrer 方法进行统计,实现移动端 / Firefox / Safari 等浏览器的准确统计。
  • 使用 Json 回调,不再使用不蒜子的 JSONP 回调方法,防止 CSRF 攻击,详情请看:JSONP
  • 初始化自动同步 (site_pv, site_uv, page_pv) 所有不蒜子的数据,无需手动操作
  • 自动保持和不蒜子的数据同步,每访问一次,数据就会自动同步
  • 兼容不蒜子的 span 标签,可以无缝切换
  • 使用 Upstash Redis 作为数据存储,数据不会丢失,保证 99.99% 可用性
  • 使用 Vercel Serverless Functions 作为后端,保证 99.99% 可用性

为什么要做这个项目?

不蒜子是一个很好的网站计数器,但是它的缺点也很明显:

  • 不蒜子速度慢,不稳定,经常会出现 502 错误。
  • 不蒜子的代码已经过时,使用的是 Referrer 方法进行统计,这种方法在移动端 / Firefox / Safari 上统计不准确。
  • 不蒜子的代码使用的是 JSONP 回调,这种方法容易受到 CSRF 攻击,威胁网站安全,详情请看:JSONP

这个项目的目的就是为了解决这些问题,让网站计数器更快,更稳定,更安全。无需自己部署,无需自己维护,只需要引入一个 script 标签就可以使用。

后续会增加更多的功能,比如:自定义网站统计数据等。

项目官网

从不蒜子切换到 Vercount

直接替换不蒜子的 script 标签即可,其他保持相同。数据会在初次访问时自动从不蒜子同步,使用时,也会自动保持和不蒜子的数据同步(当然是在不蒜子不挂的前提下,Vercount 会自动回调给不蒜子)。

替换为**访问优化版本:

<script defer src="https://cn.vercount.one/js"></script>

或者,替换为海外访问优化版本:

<script defer src="https://vercount.one/js"></script>

快速使用

将这个 script (**访问优化) 添加到你的网站中,

<script defer src="https://cn.vercount.one/js"></script>

或者这个 script (海外访问优化) 添加到你的网站中,

<script defer src="https://vercount.one/js"></script>

在你的网站中添加上面其中之一的 script 之后,和不蒜子一样,你的网站就可以开始统计了,比如。

本文总阅读量 <span id="busuanzi_value_page_pv">Loading</span> 次
本文总访客量 <span id="busuanzi_value_page_uv">Loading</span> 人
本站总访问量 <span id="busuanzi_value_site_pv">Loading</span> 次
本站总访客数 <span id="busuanzi_value_site_uv">Loading</span>

统计方式

对于 page_view 网站访问量, 每访问一次加一.

对于 user_view 访客量, 会通过用户浏览器的 UserAgent 以及用户的IP地址 进行判断.

Disclaimer

最终解释权归 EvanNotFound 所有。

vercount's People

Contributors

evannotfound avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vercount's Issues

考虑添加进各个hexo主题

我的博客是hexo 和 fluid 主题搭建的, fluid主题支持不蒜子,开启下就行,不用编辑代码。

因为不蒜子有移动端的问题,我转成了vercount,不过有些麻烦:

  1. 修改 _config.fluid.yml (加上?i=以忽略fluid在后面添加的部分):
  # busuanzi: https://busuanzi.ibruce.info/busuanzi/2.3/
  busuanzi: https://cn.vercount.one/js?i=
  1. 修改 themes/fluid/layout/_partial/scripts.ejs , 加了段script:
<% if ((theme.footer.statistics.enable && theme.footer.statistics.source === 'busuanzi')
  || (page.meta !== false && theme.post.meta.views.enable && theme.post.meta.views.source === 'busuanzi')) { %>

<script>

function observeAndDisplay(sourceId, targetId) {
  if (document.getElementById(sourceId)) {
    new MutationObserver(m => {
      m.forEach(m => {
        if (m.target.textContent.trim() !== '') {
          document.getElementById(targetId).style.display = 'inline';
        }
      });
    })
      .observe(
        document.getElementById(sourceId),
        { childList: true, characterData: true, subtree: true }
      ); 
  }
    
} 

observeAndDisplay('busuanzi_value_page_pv', 'busuanzi_container_page_pv');
observeAndDisplay('busuanzi_value_site_pv', 'busuanzi_container_site_pv');
observeAndDisplay('busuanzi_value_site_uv', 'busuanzi_container_site_uv');
    

</script> 

  <%- js_ex(theme.static_prefix.busuanzi, 'busuanzi.pure.mini.js', 'defer') %>
<% } %>

可以考虑添加进各个hexo主题,改成用vercount统计不用这么麻烦

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.