侧边栏壁纸
博主头像
琉璃红梅 博主等级

琉璃世界,白雪红梅。

  • 累计撰写 44 篇文章
  • 累计创建 90 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Halo系列-替换不蒜子统计为Vercount统计

雪穗
2025-07-14 / 0 评论 / 0 点赞 / 18 阅读 / 0 字
温馨提示:
若部分素材不小心影响到您的利益,请联系我删除。

不蒜子官网 已经无法访问了,博客页脚的访问数据也随之清空,不太清楚这是暂时关闭的还是永久关闭,但是随着使用不蒜子统计人数的增加,官网的服务器压力也越来越大,时不时502,所以我趁此更换一下博客统计的api。由于不蒜子统计代码比较“古老”以及前面所诉原因,所以有不少博主改进了统计代码并且为爱发电自建统计服务器,只要引入他们自己的api文件,可以在原有不蒜子统计数据的基础上继续统计,替换不蒜子统计的服务还是比较多的,比如 自建不蒜子APIVercount: 一个比不蒜子更好的网站计数器不蒜子

Vercount官网:https://vercount.one/

Vercount可以修改统计数据,只需要在官网登录控制台然后添加并验证自己需要进行统计的网站域名,终于吃上了不蒜子多年以前就画的饼。所以以Vercount为例,对于Joe3主题只需要将 templates\assets\lib\busuanzi\busuanzi.min.js 文件中的第55行的内容替换即可。

原内容
var bszCaller,bszTag;!function(){var c,d,e,a=!1,b=[];ready=function(c){return a||"interactive"===document.readyState||"complete"===document.readyState?c.call(document):b.push(function(){return c.call(this)}),this},d=function(){for(var a=0,c=b.length;c>a;a++)b[a].apply(document);b=[]},e=function(){a||(a=!0,d.call(window),document.removeEventListener?document.removeEventListener("DOMContentLoaded",e,!1):document.attachEvent&&(document.detachEvent("onreadystatechange",e),window==window.top&&(clearInterval(c),c=null)))},document.addEventListener?document.addEventListener("DOMContentLoaded",e,!1):document.attachEvent&&(document.attachEvent("onreadystatechange",function(){/loaded|complete/.test(document.readyState)&&e()}),window==window.top&&(c=setInterval(function(){try{a||document.documentElement.doScroll("left")}catch(b){return}e()},5)))}(),bszCaller={fetch:function(a,b){var c="BusuanziCallback_"+Math.floor(1099511627776*Math.random());window[c]=this.evalCall(b),a=a.replace("=BusuanziCallback","="+c),scriptTag=document.createElement("SCRIPT"),scriptTag.type="text/javascript",scriptTag.defer=!0,scriptTag.src=a,scriptTag.referrerPolicy="no-referrer-when-downgrade",document.getElementsByTagName("HEAD")[0].appendChild(scriptTag)},evalCall:function(a){return function(b){ready(function(){try{a(b),scriptTag.parentElement.removeChild(scriptTag)}catch(c){bszTag.hides()}})}}},bszCaller.fetch("//busuanzi.ibruce.info/busuanzi?jsonpCallback=BusuanziCallback",function(a){bszTag.texts(a),bszTag.shows()}),bszTag={bszs:["site_pv","page_pv","site_uv"],texts:function(a){this.bszs.map(function(b){var c=document.getElementById("busuanzi_value_"+b);c&&(c.innerHTML=numberToHans(a[b]))})},hides:function(){this.bszs.map(function(a){var b=document.getElementById("busuanzi_container_"+a);b&&(b.style.display="none")})},shows:function(){this.bszs.map(function(a){var b=document.getElementById("busuanzi_container_"+a);b&&(b.style.display="inline")})}};

新内容
var t,e;!function(){var n,o=[],a=!1;function r(){a=!0,document.removeEventListener("DOMContentLoaded",r),o.forEach((t=>t.call(document))),o=[]}const s=(t=2)=>`https://events.vercount.one/api/v${t}/log`;t={fetch:async function(t){const o=s(2),a=s(1);try{e.hideAll();const r=(()=>{const t=`${window.screen.width}x${window.screen.height}x${window.screen.colorDepth}`,e=Intl.DateTimeFormat().resolvedOptions().timeZone||"",n=navigator.languages?navigator.languages.join(","):navigator.language||"",o=document.createElement("canvas").getContext("webgl"),a=o?o.getParameter(o.RENDERER):"",r=[t,e,n,navigator.userAgent,a,(new Date).getTimezoneOffset()].join("|");let s=0;for(let t=0;t<r.length;t++)s=(s<<5)-s+r.charCodeAt(t),s&=s;return Math.abs(s).toString(36)})(),s=window.location.href;let i=s;s.startsWith("http")||(console.warn("Invalid URL protocol detected. Only HTTP and HTTPS are supported."),i="https://local.file/invalid-protocol");try{const a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","X-Browser-Token":r},body:JSON.stringify({url:i,token:r})});if(!a.ok)throw new Error(`API responded with status: ${a.status}`);const s=(t=>{if(t&&t.status){if("success"===t.status&&t.data)return t.data;if("error"===t.status&&t.data)return console.warn(`API error: ${t.message}`,t),t.data;if("error"===t.status)return console.warn(`API error: ${t.message}`,t),{site_uv:0,site_pv:0,page_pv:0}}return t||{site_uv:0,site_pv:0,page_pv:0}})(await a.json());n((()=>{t(s),localStorage.setItem("visitorCountData",JSON.stringify(s)),e.showAll()}))}catch(o){console.warn("Error with v2 API, falling back to v1:",o);try{const o=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json","X-Browser-Token":r},body:JSON.stringify({url:i,token:r})}),s=await o.json();n((()=>{t(s),localStorage.setItem("visitorCountData",JSON.stringify(s)),e.showAll()}))}catch(o){console.warn("CORS error with token header, retrying without custom header:",o);const s=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:i,token:r})}),c=await s.json();n((()=>{t(c),localStorage.setItem("visitorCountData",JSON.stringify(c)),e.showAll()}))}}}catch(o){console.error("Error fetching visitor count:",o);const a=localStorage.getItem("visitorCountData");if(a)try{const o=JSON.parse(a);n((()=>{t(o),e.showAll()})),console.log("Using cached visitor count data")}catch(t){console.error("Error parsing cached data:",t),e.hideAll()}else e.hideAll()}}},e={counterIds:["site_pv","page_pv","site_uv"],updateText:function(t){this.counterIds.forEach((e=>{const n=document.getElementById("busuanzi_value_"+e);n&&(n.textContent=t[e]||"0");const o=document.getElementById("vercount_value_"+e);o&&(o.textContent=t[e]||"0")}))},hideAll:function(){this.counterIds.forEach((t=>{const e=document.getElementById("busuanzi_container_"+t);e&&(e.style.display="none");const n=document.getElementById("vercount_container_"+t);n&&(n.style.display="none")}))},showAll:function(){this.counterIds.forEach((t=>{const e=document.getElementById("busuanzi_container_"+t);e&&(e.style.display="inline");const n=document.getElementById("vercount_container_"+t);n&&(n.style.display="inline")}))}},(n=function(t){a||"interactive"===document.readyState||"complete"===document.readyState?t.call(document):(o.push(t),document.addEventListener("DOMContentLoaded",r))})((()=>{t.fetch(e.updateText.bind(e))}))}();

Vercount完全“兼容”不蒜子统计,如果不蒜子统计服务正常,在替换为Vercount统计后会从不蒜子服务器同步访问数据,如果不蒜子服务无法访问,则原来的统计的访问数据将从零开始重新计数。此外Vercount也是个人维护,随着成本的增加不排除跑路的可能,如果你的网站的访问数据特别重要,建议自己搭建服务。

网站验证步骤如下,添加网站域名后,前往域名解析商在DNS解析里添加TXT记录,然后回到原页面点击 check verification 进行验证,如果你不需要修改统计数据则无须登录控制台。

vercount_20250714160604.avif

vercount_20250714160755.avif

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区