MediaWiki:Common.js:修订间差异
外观
Maintenance script(留言 | 贡献) 精准去下拉 |
Maintenance script(留言 | 贡献) 加访客统计页脚 |
||
| 第1行: | 第1行: | ||
/ | // 访客计数:页脚显示「本站累计访问 X 次 · 今日 Y 次(Z 位访客)」 | ||
// 数据来自 /stats.json(服务器每 5 分钟由日志生成),浏览器缓存 5 分钟,开销可忽略。 | |||
(function () { | |||
function fmt(n) { | |||
try { return Number(n).toLocaleString('en-US'); } | |||
} | catch (e) { return n; } | ||
} | |||
// 只在页面完全加载后请求一次,不阻塞渲染 | |||
function run() { | |||
fetch('/stats.json', { credentials: 'omit' }).then(function (r) { | |||
} ); | return r.ok ? r.json() : null; | ||
}).then(function (d) { | |||
} ); | if (!d || typeof d.total_views === 'undefined') return; | ||
var ul = document.querySelector('#footer-info ul') || | |||
document.querySelector('#footer ul'); | |||
if (!ul || document.getElementById('footer-site-stats')) return; | |||
var li = document.createElement('li'); | |||
li.id = 'footer-site-stats'; | |||
li.textContent = '本站累计访问 ' + fmt(d.total_views) + ' 次 · 今日 ' + | |||
fmt(d.today_views) + ' 次(' + fmt(d.today_visitors) + ' 位访客)'; | |||
ul.appendChild(li); | |||
}).catch(function () { /* 统计失败不影响页面 */ }); | |||
} | |||
if (document.readyState === 'complete') run(); | |||
else window.addEventListener('load', run); | |||
})(); | |||
2026年10月11日 (日) 14:44的版本
// 访客计数:页脚显示「本站累计访问 X 次 · 今日 Y 次(Z 位访客)」
// 数据来自 /stats.json(服务器每 5 分钟由日志生成),浏览器缓存 5 分钟,开销可忽略。
(function () {
function fmt(n) {
try { return Number(n).toLocaleString('en-US'); }
catch (e) { return n; }
}
// 只在页面完全加载后请求一次,不阻塞渲染
function run() {
fetch('/stats.json', { credentials: 'omit' }).then(function (r) {
return r.ok ? r.json() : null;
}).then(function (d) {
if (!d || typeof d.total_views === 'undefined') return;
var ul = document.querySelector('#footer-info ul') ||
document.querySelector('#footer ul');
if (!ul || document.getElementById('footer-site-stats')) return;
var li = document.createElement('li');
li.id = 'footer-site-stats';
li.textContent = '本站累计访问 ' + fmt(d.total_views) + ' 次 · 今日 ' +
fmt(d.today_views) + ' 次(' + fmt(d.today_visitors) + ' 位访客)';
ul.appendChild(li);
}).catch(function () { /* 统计失败不影响页面 */ });
}
if (document.readyState === 'complete') run();
else window.addEventListener('load', run);
})();