Новые изменения

This commit is contained in:
Web-serfer 2026-04-27 01:04:06 +05:00
parent dc00e31578
commit e621b3c40e
8 changed files with 234 additions and 54 deletions

View file

@ -314,20 +314,15 @@ const {
const viewsEl = document.querySelector('.meta-views') as HTMLElement & { dataset: { postId: string } };
if (viewsEl?.dataset?.postId) {
const postId = viewsEl.dataset.postId;
const hasViewed = sessionStorage.getItem(`viewed_${postId}`);
if (!hasViewed) {
fetch(`/api/increment-views?postId=${postId}`, { method: 'POST' })
.then(res => res.json())
.then(data => {
if (data.views !== undefined) {
viewsEl.textContent = formatViews(data.views);
}
})
.catch(() => {});
sessionStorage.setItem(`viewed_${postId}`, 'true');
}
fetch(`/api/increment-views?postId=${postId}`, { method: 'POST' })
.then(res => res.json())
.then(data => {
if (data.views !== undefined) {
viewsEl.textContent = formatViews(data.views);
}
})
.catch(() => {});
}
function formatViews(n: number): string {