加入流量查看,访客与视频数量图片数量查看
This commit is contained in:
@@ -14,6 +14,44 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const videoWrap = document.getElementById('videoWrap');
|
||||
const videoPanel = document.getElementById('video');
|
||||
const includeLocalToggle = document.getElementById('includeLocalToggle');
|
||||
const statFlowEl = document.getElementById('statFlow');
|
||||
const statVisitEl = document.getElementById('statVisit');
|
||||
const statVideoEl = document.getElementById('statVideo');
|
||||
const statPicEl = document.getElementById('statPic');
|
||||
const formatBytes = (n) => {
|
||||
let val = Number(n) || 0;
|
||||
const units = ['B','KB','MB','GB','TB','PB','EB','ZB','YB'];
|
||||
let i = 0;
|
||||
while (val >= 1024 && i < units.length - 1) { val /= 1024; i++; }
|
||||
const digits = val >= 100 ? 0 : (val >= 10 ? 1 : 2);
|
||||
return val.toFixed(digits) + ' ' + units[i];
|
||||
};
|
||||
const formatCount = (n) => {
|
||||
if (n >= 100000000) return (n / 100000000).toFixed(n < 1000000000 ? 2 : 1) + ' 亿';
|
||||
if (n >= 10000) return (n / 10000).toFixed(n < 100000 ? 2 : 1) + ' 万';
|
||||
return new Intl.NumberFormat('zh-CN').format(n);
|
||||
};
|
||||
const updateStatsUI = (t) => {
|
||||
if (!t) return;
|
||||
const bw = (t.bandwidth_in ?? 0) + (t.bandwidth_out ?? 0);
|
||||
if (statFlowEl) statFlowEl.textContent = formatBytes(bw);
|
||||
if (statVisitEl) statVisitEl.textContent = formatCount(t.visits ?? 0);
|
||||
if (statVideoEl) statVideoEl.textContent = formatCount(t.video_plays ?? 0);
|
||||
if (statPicEl) statPicEl.textContent = formatCount(t.picture_shows ?? 0);
|
||||
};
|
||||
const track = async (payload) => {
|
||||
try {
|
||||
const r = await fetch('api/stats.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const j = await r.json();
|
||||
if (j && j.success && j.today) updateStatsUI(j.today);
|
||||
} catch {}
|
||||
};
|
||||
(async () => { try { const r = await fetch('api/stats.php'); const j = await r.json(); if (j && j.success && j.today) updateStatsUI(j.today); } catch {} })();
|
||||
track({ event: 'visit', page: location.pathname });
|
||||
// 底部工具栏与标题已移除,无需获取相关元素
|
||||
|
||||
if (!player || !videoWrap) return; // 仅在视频区存在时执行
|
||||
@@ -332,6 +370,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
pictureImg.src = url;
|
||||
picLastSwap = Date.now();
|
||||
if (galleryPanel) galleryPanel.style.setProperty('--pic-progress', '0');
|
||||
track({ event: 'picture_show', page: location.pathname, url });
|
||||
if (pictureWrap.matches(':hover')) showPic();
|
||||
}
|
||||
})();
|
||||
@@ -341,6 +380,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
pictureImg.src = url;
|
||||
picLastSwap = Date.now();
|
||||
if (galleryPanel) galleryPanel.style.setProperty('--pic-progress', '0');
|
||||
track({ event: 'picture_show', page: location.pathname, url });
|
||||
if (pictureWrap.matches(':hover')) showPic();
|
||||
}
|
||||
}, picIntervalMs);
|
||||
|
||||
Reference in New Issue
Block a user