Новая логику счетчика посетилей

This commit is contained in:
Web-serfer 2026-05-01 23:24:48 +05:00
parent 18762aaaaf
commit 3fa295e076
2 changed files with 22 additions and 4 deletions

View file

@ -29,8 +29,13 @@ const { today = 0, total = 0 } = Astro.props;
if (valueEls.length < 2) return;
const todayStr = new Date().toDateString();
const lastVisit = localStorage.getItem('site_visited');
fetch('/api/visitors').then(r => r.json()).then(d => {
// Если уже посещали сегодня - помечаем как повторный визит
const isRepeat = lastVisit === todayStr;
const apiUrl = isRepeat ? '/api/visitors?repeat=true' : '/api/visitors';
fetch(apiUrl).then(r => r.json()).then(d => {
if (typeof d.todayVisitors === 'number') {
if (d.isNewVisitor) {
localStorage.setItem('site_visited', todayStr);