(function(){
function init(){
var collapsed=false;
var btn=document.createElement('div');
btn.id='stats-toggle';
btn.title='\u7EDF\u8BA1';
btn.innerHTML='\u{1F4CA}';
btn.onclick=function(){
collapsed=!collapsed;
c.style.display=collapsed?'none':'block';
btn.innerHTML=collapsed?'\u{1F4CA}':'\u2715';
};
var c=document.createElement('div');
c.id='stats-card';
c.innerHTML='
\u{1F4CA} \u5E73\u53F0\u7EDF\u8BA1
'
+'\u603BToken-
'
+'\u8F93\u5165-
'
+'\u8F93\u51FA-
'
+'\u8BF7\u6C42-
'
+'\u6D3B\u8DC3\u7528\u6237-
';
document.body.appendChild(btn);
document.body.appendChild(c);
loadStats();
setInterval(loadStats,60000);
}
function loadStats(){
fetch('/api/stats').then(function(r){return r.json()}).then(function(d){
document.getElementById('st-tk').textContent=(d.total_tokens/1e6).toFixed(1)+'M';
document.getElementById('st-pt').textContent=(d.prompt_tokens/1e6).toFixed(1)+'M';
document.getElementById('st-ct').textContent=(d.completion_tokens/1e6).toFixed(1)+'M';
document.getElementById('st-rq').textContent=d.total_requests.toLocaleString();
document.getElementById('st-ur').textContent=d.active_users;
}).catch(function(){});
}
var s=document.createElement('style');
s.textContent='#stats-toggle{position:fixed;bottom:24px;right:24px;z-index:100000;width:40px;height:40px;border-radius:50%;background:linear-gradient(135deg,#667eea,#764ba2);color:#fff;display:flex;align-items:center;justify-content:center;font-size:18px;cursor:pointer;box-shadow:0 2px 12px rgba(0,0,0,.25);transition:transform .2s}#stats-toggle:hover{transform:scale(1.1)}'
+'#stats-card{position:fixed;bottom:74px;right:24px;z-index:99999;background:rgba(30,30,46,.95);color:#e0e0e0;padding:16px 20px;border-radius:12px;font-size:13px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;box-shadow:0 4px 24px rgba(0,0,0,.25);backdrop-filter:blur(8px);min-width:180px}'
+'#stats-card .sc-title{font-size:14px;font-weight:600;margin-bottom:10px;color:#fff;border-bottom:1px solid rgba(255,255,255,.15);padding-bottom:8px}'
+'#stats-card .sc-row{display:flex;justify-content:space-between;padding:3px 0}'
+'#stats-card .sc-val{font-weight:700;color:#667eea}';
document.head.appendChild(s);
if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',init)}else{init()}
})();