q78kgblog / js /commentsCount.js
Q78KG's picture
Site updated: 2024-10-23 23:23:31
779c5fe
raw
history blame contribute delete
860 Bytes
function comCount(){let t=loadData("comCount",10);t?document.querySelectorAll(".card_comment").forEach(e=>{e.innerHTML=t}):fetch("https://twikoo.yumetsuki.moe/",{method:"POST",body:JSON.stringify({event:"COMMENT_GET_FOR_ADMIN",accessToken:"1059857c25a2ce9fba9cff298f4f33ee",per:1,page:1}),headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{document.querySelectorAll(".card_comment").forEach(n=>{n.innerHTML=e.count}),document.getElementsByClassName("card_comment").innerText=e.count,saveData("comCount",e.count)})}function saveData(t,e){localStorage.setItem(t,JSON.stringify({time:Date.now(),data:e}))}function loadData(t,e){let n=JSON.parse(localStorage.getItem(t)),o=0;return n!=null&&(o=Date.now()-n.time),o<e*60*1e3&&o>0?n.data:0}window.addEventListener("pjax:complete",comCount),window.addEventListener("DOMContentLoaded",comCount);