Новая логику счетчика посетилей
This commit is contained in:
parent
18762aaaaf
commit
3fa295e076
2 changed files with 22 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue