-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquota_viewer.html
More file actions
654 lines (600 loc) · 26.2 KB
/
quota_viewer.html
File metadata and controls
654 lines (600 loc) · 26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quota Viewer</title>
<style>
:root {
--bg: #313338;
--card-bg: #2b2d31;
--border: #3f4147;
--text: #f2f3f5;
--text-secondary: #b5bac1;
--success: #23a559;
--warning: #f0b232;
--danger: #f23f43;
--primary: #5865f2;
--antigravity: #00a8fc;
--codex: #fee75c;
--gemini-cli: #57f287;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.5;
padding: 12px;
}
.container { max-width: 1400px; margin: 0 auto; }
h1 { text-align: center; margin-bottom: 12px; font-size: 1.4rem; }
.upload-area {
border: 2px dashed var(--border);
border-radius: 6px;
padding: 20px;
text-align: center;
margin-bottom: 12px;
background: var(--card-bg);
cursor: pointer;
transition: border-color 0.2s;
}
.upload-area:hover { border-color: var(--primary); background: #2d3238; }
.upload-area input { display: none; }
.upload-area p { color: var(--text-secondary); font-size: 0.85rem; }
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 10px;
margin-bottom: 12px;
}
.stat-card {
background: var(--card-bg);
border-radius: 6px;
padding: 10px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.stat-header { text-align: center; margin-bottom: 8px; }
.stat-card .value { font-size: 1.4rem; font-weight: 700; }
.stat-card .label { color: var(--text-secondary); font-size: 0.8rem; }
.stat-card.antigravity { background: color-mix(in srgb, var(--antigravity) 15%, var(--card-bg)); }
.stat-card.antigravity .value { color: var(--antigravity); }
.stat-card.codex { background: color-mix(in srgb, var(--codex) 15%, var(--card-bg)); }
.stat-card.codex .value { color: var(--codex); }
.stat-card.gemini-cli { background: color-mix(in srgb, var(--gemini-cli) 15%, var(--card-bg)); }
.stat-card.gemini-cli .value { color: var(--gemini-cli); }
.agg-quotas { border-top: 1px solid var(--border); padding-top: 8px; }
.agg-quota-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 3px 0;
font-size: 0.8rem;
}
.agg-label { color: var(--text-secondary); }
.agg-percent { font-weight: 600; }
.agg-percent.high { color: var(--success); }
.agg-percent.medium { color: var(--warning); }
.agg-percent.low { color: var(--danger); }
.filter-bar {
display: flex;
gap: 8px;
margin-bottom: 12px;
flex-wrap: wrap;
}
.filter-btn {
padding: 4px 12px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--card-bg);
color: var(--text);
cursor: pointer;
font-size: 0.8rem;
transition: all 0.2s;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.card {
background: var(--card-bg);
border-radius: 6px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
overflow: hidden;
}
.card.antigravity { background: color-mix(in srgb, var(--antigravity) 15%, var(--card-bg)); }
.card.codex { background: color-mix(in srgb, var(--codex) 15%, var(--card-bg)); }
.card.gemini-cli { background: color-mix(in srgb, var(--gemini-cli) 15%, var(--card-bg)); }
.card-header {
padding: 8px 12px;
border-bottom: 1px solid var(--border);
}
.card-header .name {
font-weight: 600;
font-size: 0.85rem;
word-break: break-all;
}
.card-body { padding: 10px 12px; }
.quota-list { list-style: none; }
.quota-item {
padding: 6px 0;
border-bottom: 1px solid var(--border);
}
.quota-item:last-child { border-bottom: none; }
.quota-item .label { font-size: 0.8rem; color: var(--text); }
.quota-item .info-row { display: flex; align-items: center; gap: 8px; }
.quota-item .percent { font-weight: 700; font-size: 0.9rem; }
.quota-item .reset { font-size: 0.7rem; color: var(--text-secondary); }
.plan-tag {
font-size: 0.75rem;
font-weight: 600;
color: var(--text-secondary);
margin-bottom: 4px;
}
.progress-bar {
width: 100%;
height: 4px;
background: #4e5058;
border-radius: 2px;
margin-top: 4px;
overflow: hidden;
}
.progress-bar .fill {
height: 100%;
border-radius: 3px;
transition: width 0.3s;
}
.fill.high { background: var(--success); }
.fill.medium { background: var(--warning); }
.fill.low { background: var(--danger); }
.error-msg { color: var(--danger); font-size: 0.75rem; padding: 4px 0; }
.empty { text-align: center; padding: 30px 12px; color: var(--text-secondary); font-size: 0.85rem; }
@media (max-width: 600px) {
.cards { grid-template-columns: 1fr; }
.stats { grid-template-columns: 1fr 1fr; }
}
</style>
</head>
<body>
<div class="container">
<h1>Quota Viewer</h1>
<div id="status"></div>
<div id="content"></div>
</div>
<script>
const content = document.getElementById('content');
const statusEl = document.getElementById('status');
function getKeyFromUrl() {
return new URLSearchParams(window.location.search).get('key') || '';
}
async function loadData() {
const key = getKeyFromUrl();
if (!key) {
content.innerHTML = '<p class="error-msg">缺少访问 key</p>';
return;
}
statusEl.textContent = '加载中...';
content.innerHTML = '';
try {
const resp = await fetch(`/api/quota?key=${encodeURIComponent(key)}`, { cache: 'no-store' });
if (!resp.ok) throw new Error(`接口返回 ${resp.status}`);
const data = await resp.json();
statusEl.textContent = '';
renderData(data);
} catch (err) {
statusEl.textContent = '';
content.innerHTML = '<p class="error-msg">获取数据失败: ' + err.message + '</p>';
}
}
function parseBody(bodyStr) {
if (!bodyStr) return null;
try {
const outer = typeof bodyStr === 'string' ? JSON.parse(bodyStr) : bodyStr;
if (outer.body) {
return typeof outer.body === 'string' ? JSON.parse(outer.body) : outer.body;
}
return outer;
} catch { return null; }
}
function formatResetTime(t) {
if (!t) return '-';
const d = new Date(t);
if (isNaN(d.getTime())) return '-';
return d.toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false });
}
function normalizeNumberValue(value) {
if (typeof value === 'number' && Number.isFinite(value)) return value;
if (typeof value === 'string') {
const trimmed = value.trim();
if (!trimmed) return null;
const parsed = Number(trimmed);
return Number.isFinite(parsed) ? parsed : null;
}
return null;
}
function normalizeQuotaFraction(value) {
const normalized = normalizeNumberValue(value);
if (normalized !== null) return normalized;
if (typeof value === 'string' && value.trim().endsWith('%')) {
const parsed = Number(value.trim().slice(0, -1));
return Number.isFinite(parsed) ? parsed / 100 : null;
}
return null;
}
function parseResetFromWindow(window) {
if (!window) return '-';
const resetAt = normalizeNumberValue(window.reset_at ?? window.resetAt);
if (resetAt && resetAt > 0) return formatUnixSeconds(resetAt);
const resetAfter = normalizeNumberValue(window.reset_after_seconds ?? window.resetAfterSeconds);
if (resetAfter && resetAfter > 0) {
const targetSeconds = Math.floor(Date.now() / 1000 + resetAfter);
return formatUnixSeconds(targetSeconds);
}
return '-';
}
function formatUnixSeconds(value) {
if (!value) return '-';
const d = new Date(value * 1000);
if (isNaN(d.getTime())) return '-';
return d.toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false });
}
const ANTIGRAVITY_GROUPS = [
{ id: 'claude-gpt', label: 'Claude/GPT', identifiers: ['claude-sonnet-4-5-thinking', 'claude-opus-4-5-thinking', 'claude-sonnet-4-5', 'gpt-oss-120b-medium'] },
{ id: 'gemini-3-pro', label: 'Gemini 3 Pro', identifiers: ['gemini-3-pro-high', 'gemini-3-pro-low'] },
{ id: 'gemini-2-5-flash', label: 'Gemini 2.5 Flash', identifiers: ['gemini-2.5-flash', 'gemini-2.5-flash-thinking'] },
{ id: 'gemini-2-5-flash-lite', label: 'Gemini 2.5 Flash Lite', identifiers: ['gemini-2.5-flash-lite'] },
{ id: 'gemini-2-5-cu', label: 'Gemini 2.5 CU', identifiers: ['rev19-uic3-1p'] },
{ id: 'gemini-3-flash', label: 'Gemini 3 Flash', identifiers: ['gemini-3-flash'] },
{ id: 'gemini-image', label: 'Gemini 3 Pro Image', identifiers: ['gemini-3-pro-image'], labelFromModel: true },
];
function getAntigravityQuotaInfo(entry) {
if (!entry) return { remainingFraction: null };
const quotaInfo = entry.quotaInfo ?? entry.quota_info ?? {};
const remainingValue = quotaInfo.remainingFraction ?? quotaInfo.remaining_fraction ?? quotaInfo.remaining;
const remainingFraction = normalizeQuotaFraction(remainingValue);
const resetValue = quotaInfo.resetTime ?? quotaInfo.reset_time;
const resetTime = typeof resetValue === 'string' ? resetValue : undefined;
const displayName = typeof entry.displayName === 'string' ? entry.displayName : undefined;
return { remainingFraction, resetTime, displayName };
}
function findAntigravityModel(models, identifier) {
if (models[identifier]) return { id: identifier, entry: models[identifier] };
const match = Object.entries(models).find(([, entry]) => {
const name = typeof entry?.displayName === 'string' ? entry.displayName : '';
return name.toLowerCase() === identifier.toLowerCase();
});
if (match) return { id: match[0], entry: match[1] };
return null;
}
function buildAntigravityGroups(models) {
const groups = [];
let geminiProResetTime;
const buildGroup = (def, overrideResetTime) => {
const matches = def.identifiers.map(id => findAntigravityModel(models, id)).filter(Boolean);
const quotaEntries = matches.map(({ id, entry }) => {
const info = getAntigravityQuotaInfo(entry);
const remainingFraction = info.remainingFraction ?? (info.resetTime ? 0 : null);
if (remainingFraction === null) return null;
return { id, remainingFraction, resetTime: info.resetTime, displayName: info.displayName };
}).filter(Boolean);
if (!quotaEntries.length) return null;
const remainingFraction = Math.min(...quotaEntries.map(e => e.remainingFraction));
const resetTime = overrideResetTime ?? quotaEntries.map(e => e.resetTime).find(Boolean);
const displayName = quotaEntries.map(e => e.displayName).find(Boolean);
const label = def.labelFromModel && displayName ? displayName : def.label;
return { id: def.id, label, remainingFraction, resetTime };
};
const claudeGroup = buildGroup(ANTIGRAVITY_GROUPS[0]);
if (claudeGroup) groups.push(claudeGroup);
const geminiProGroup = buildGroup(ANTIGRAVITY_GROUPS[1]);
if (geminiProGroup) {
geminiProResetTime = geminiProGroup.resetTime;
groups.push(geminiProGroup);
}
for (const def of ANTIGRAVITY_GROUPS.slice(2, 5)) {
const g = buildGroup(def);
if (g) groups.push(g);
}
const geminiFlashGroup = buildGroup(ANTIGRAVITY_GROUPS[5]);
if (geminiFlashGroup) groups.push(geminiFlashGroup);
const imageGroup = buildGroup(ANTIGRAVITY_GROUPS[6], geminiProResetTime);
if (imageGroup) groups.push(imageGroup);
return groups;
}
function extractAntigravityQuota(body) {
const parsed = parseBody(body);
if (!parsed || !parsed.models) return [];
const groups = buildAntigravityGroups(parsed.models);
return groups.map(g => ({
label: g.label,
percent: Math.round((g.remainingFraction ?? 0) * 100),
reset: g.resetTime
}));
}
const GEMINI_GROUPS = [
{ id: 'gemini-flash-series', label: 'Gemini Flash Series', preferredModelId: 'gemini-3-flash-preview', modelIds: ['gemini-3-flash-preview', 'gemini-2.5-flash', 'gemini-2.5-flash-lite'] },
{ id: 'gemini-pro-series', label: 'Gemini Pro Series', preferredModelId: 'gemini-3-pro-preview', modelIds: ['gemini-3-pro-preview', 'gemini-2.5-pro'] },
];
const GEMINI_GROUP_LOOKUP = new Map(GEMINI_GROUPS.flatMap(g => g.modelIds.map(id => [id, g])));
const GEMINI_CLI_IGNORED_PREFIXES = ['gemini-2.0-flash'];
function isIgnoredGeminiCliModel(modelId) {
return GEMINI_CLI_IGNORED_PREFIXES.some(prefix => modelId && modelId.startsWith(prefix));
}
function extractGeminiCliQuota(body) {
const parsed = parseBody(body);
if (!parsed || !parsed.buckets) return [];
const grouped = new Map();
parsed.buckets.forEach(bucket => {
const modelId = bucket.modelId ?? bucket.model_id;
if (!modelId || isIgnoredGeminiCliModel(modelId)) return;
const group = GEMINI_GROUP_LOOKUP.get(modelId);
const groupId = group?.id ?? modelId;
const label = group?.label ?? modelId;
const tokenKey = bucket.tokenType ?? bucket.token_type ?? '';
const mapKey = `${groupId}::${tokenKey}`;
const existing = grouped.get(mapKey);
const remainingFraction = normalizeQuotaFraction(bucket.remainingFraction ?? bucket.remaining_fraction);
const remainingAmount = normalizeNumberValue(bucket.remainingAmount ?? bucket.remaining_amount);
const resetTime = bucket.resetTime ?? bucket.reset_time;
if (!existing) {
const preferredModelId = group?.preferredModelId;
const preferredBucket = preferredModelId && modelId === preferredModelId ? bucket : undefined;
grouped.set(mapKey, {
label,
tokenType: tokenKey,
preferredModelId,
preferredBucket,
fallbackRemainingFraction: remainingFraction,
fallbackRemainingAmount: remainingAmount,
fallbackResetTime: resetTime,
});
return;
}
existing.fallbackRemainingFraction = Math.min(
existing.fallbackRemainingFraction ?? remainingFraction ?? 1,
remainingFraction ?? existing.fallbackRemainingFraction ?? 1
);
existing.fallbackRemainingAmount = Math.min(
existing.fallbackRemainingAmount ?? remainingAmount ?? 0,
remainingAmount ?? existing.fallbackRemainingAmount ?? 0
);
existing.fallbackResetTime = existing.fallbackResetTime || resetTime;
if (existing.preferredModelId && modelId === existing.preferredModelId) {
existing.preferredBucket = bucket;
}
});
return Array.from(grouped.values()).map(bucket => {
const preferred = bucket.preferredBucket;
const remainingFraction = preferred
? normalizeQuotaFraction(preferred.remainingFraction ?? preferred.remaining_fraction)
: bucket.fallbackRemainingFraction;
const resetTime = preferred ? preferred.resetTime ?? preferred.reset_time : bucket.fallbackResetTime;
const label = bucket.tokenType ? `${bucket.label} (${bucket.tokenType})` : bucket.label;
return {
label,
percent: Math.round((remainingFraction ?? 0) * 100),
reset: resetTime
};
});
}
function extractCodexQuota(body) {
const parsed = parseBody(body);
if (!parsed) return { plan: null, items: [] };
const rateLimit = parsed.rate_limit ?? parsed.rateLimit ?? null;
const codeReviewLimit = parsed.code_review_rate_limit ?? parsed.codeReviewRateLimit ?? null;
const normalizePlanType = (value) => typeof value === 'string' ? value.trim().toLowerCase() : null;
const planType = normalizePlanType(parsed.plan_type ?? parsed.planType) || null;
const planLabel = planType ? (planType === 'plus' ? 'Plus' : planType === 'team' ? 'Team' : planType) : null;
const getWindowSeconds = (window) => normalizeNumberValue(window?.limit_window_seconds ?? window?.limitWindowSeconds);
const pickWindows = (limitInfo) => {
const windows = [limitInfo?.primary_window ?? limitInfo?.primaryWindow ?? null, limitInfo?.secondary_window ?? limitInfo?.secondaryWindow ?? null];
let fiveHour = null;
let weekly = null;
windows.forEach(w => {
const seconds = getWindowSeconds(w);
if (seconds === 18000 && !fiveHour) fiveHour = w;
if (seconds === 604800 && !weekly) weekly = w;
});
return { fiveHour, weekly };
};
const items = [];
const addWindow = (label, window, limitReached, allowed) => {
if (!window) return;
const usedPercent = normalizeNumberValue(window.used_percent ?? window.usedPercent);
let remaining = usedPercent === null ? null : Math.max(0, Math.min(100, 100 - usedPercent));
if (remaining === null && (limitReached === true || allowed === false)) remaining = 0;
items.push({
label,
percent: remaining ?? 0,
reset: parseResetFromWindow(window),
});
};
const rateWindows = pickWindows(rateLimit);
addWindow('5 小时限额', rateWindows.fiveHour, rateLimit?.limit_reached ?? rateLimit?.limitReached, rateLimit?.allowed);
addWindow('周限额', rateWindows.weekly, rateLimit?.limit_reached ?? rateLimit?.limitReached, rateLimit?.allowed);
const codeWindows = pickWindows(codeReviewLimit);
addWindow('代码审查 5 小时限额', codeWindows.fiveHour, codeReviewLimit?.limit_reached ?? codeReviewLimit?.limitReached, codeReviewLimit?.allowed);
addWindow('代码审查周限额', codeWindows.weekly, codeReviewLimit?.limit_reached ?? codeReviewLimit?.limitReached, codeReviewLimit?.allowed);
return { plan: planLabel, items };
}
function extractQuota(item) {
const provider = (item.provider || '').toLowerCase();
if (provider === 'antigravity') return extractAntigravityQuota(item.body);
if (provider === 'codex') return extractCodexQuota(item.body);
if (provider === 'gemini-cli') return extractGeminiCliQuota(item.body);
return [];
}
function getProgressClass(percent) {
if (percent >= 60) return 'high';
if (percent >= 20) return 'medium';
return 'low';
}
let currentFilter = 'all';
let allData = [];
function isDisabledItem(item) {
const disabled = item.disabled;
if (typeof disabled === 'boolean') return disabled;
if (typeof disabled === 'number') return disabled !== 0;
if (typeof disabled === 'string') return disabled.trim().toLowerCase() === 'true';
return false;
}
function isRuntimeOnlyItem(item) {
const raw = item.runtime_only ?? item.runtimeOnly;
if (typeof raw === 'boolean') return raw;
if (typeof raw === 'string') return raw.trim().toLowerCase() === 'true';
return false;
}
function shouldShowItem(item) {
if (isDisabledItem(item)) return false;
const provider = (item.provider || '').toLowerCase();
if (provider === 'gemini-cli' && isRuntimeOnlyItem(item)) return false;
return true;
}
function aggregateQuotaByProvider(data) {
const result = {
antigravity: { count: 0, quotas: {} },
codex: { count: 0, quotas: {} },
'gemini-cli': { count: 0, quotas: {} },
};
data.forEach(item => {
const provider = (item.provider || '').toLowerCase();
if (!result[provider]) return;
if (item.status !== 200) return;
result[provider].count++;
const quotas = extractQuota(item);
if (!quotas) return;
const items = provider === 'codex' ? (quotas.items || []) : (Array.isArray(quotas) ? quotas : []);
items.forEach(q => {
if (q.percent == null) return;
if (!result[provider].quotas[q.label]) {
result[provider].quotas[q.label] = { sum: 0, count: 0 };
}
result[provider].quotas[q.label].sum += q.percent;
result[provider].quotas[q.label].count++;
});
});
// Calculate averages
Object.keys(result).forEach(provider => {
const quotas = result[provider].quotas;
Object.keys(quotas).forEach(label => {
quotas[label].avg = Math.round(quotas[label].sum / quotas[label].count);
});
});
return result;
}
function renderAggregatedQuotas(providerData) {
const quotas = providerData.quotas;
const labels = Object.keys(quotas);
if (!labels.length) return '';
return labels.map(label => {
const avg = quotas[label].avg;
return `
<div class="agg-quota-item">
<span class="agg-label">${label}</span>
<span class="agg-percent ${getProgressClass(avg)}">${avg}%</span>
</div>
`;
}).join('');
}
function renderData(data) {
allData = data.filter(shouldShowItem);
const stats = { antigravity: 0, codex: 0, 'gemini-cli': 0 };
allData.forEach(item => {
const p = (item.provider || '').toLowerCase();
if (stats[p] !== undefined) stats[p]++;
});
const aggregated = aggregateQuotaByProvider(allData);
let html = `
<div class="stats">
<div class="stat-card antigravity">
<div class="stat-header"><div class="value">${stats.antigravity}</div><div class="label">Antigravity</div></div>
<div class="agg-quotas">${renderAggregatedQuotas(aggregated.antigravity)}</div>
</div>
<div class="stat-card codex">
<div class="stat-header"><div class="value">${stats.codex}</div><div class="label">Codex</div></div>
<div class="agg-quotas">${renderAggregatedQuotas(aggregated.codex)}</div>
</div>
<div class="stat-card gemini-cli">
<div class="stat-header"><div class="value">${stats['gemini-cli']}</div><div class="label">Gemini CLI</div></div>
<div class="agg-quotas">${renderAggregatedQuotas(aggregated['gemini-cli'])}</div>
</div>
</div>
<div class="filter-bar">
<button class="filter-btn ${currentFilter === 'all' ? 'active' : ''}" data-filter="all">全部</button>
<button class="filter-btn ${currentFilter === 'antigravity' ? 'active' : ''}" data-filter="antigravity">Antigravity</button>
<button class="filter-btn ${currentFilter === 'codex' ? 'active' : ''}" data-filter="codex">Codex</button>
<button class="filter-btn ${currentFilter === 'gemini-cli' ? 'active' : ''}" data-filter="gemini-cli">Gemini CLI</button>
</div>
<div class="cards" id="cardsContainer"></div>
`;
content.innerHTML = html;
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.addEventListener('click', () => {
currentFilter = btn.dataset.filter;
renderCards();
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
});
});
renderCards();
}
function renderCards() {
const container = document.getElementById('cardsContainer');
const filtered = currentFilter === 'all' ? allData : allData.filter(d => (d.provider || '').toLowerCase() === currentFilter);
if (!filtered.length) {
container.innerHTML = '<div class="empty">暂无数据</div>';
return;
}
container.innerHTML = filtered.map(item => {
const provider = (item.provider || '').toLowerCase();
const quotas = extractQuota(item);
const email = (item.name || '').replace(/^[^-]+-/, '').replace(/\.json$/, '');
let quotaHtml = '';
if (item.status !== 200) {
quotaHtml = `<p class="error-msg">请求失败 (${item.status})</p>`;
} else if (!quotas || (Array.isArray(quotas) && !quotas.length)) {
quotaHtml = `<p class="error-msg">无配额数据</p>`;
} else {
if (provider === 'codex') {
const planTag = quotas.plan ? `<div class="plan-tag">${quotas.plan}</div>` : '';
quotaHtml = `
${planTag}
<ul class="quota-list">${quotas.items.map(q => `
<li class="quota-item">
<div class="label">${q.label}</div>
<div class="info-row">
<div class="percent">${q.percent}%</div>
<div class="reset">${q.reset}</div>
</div>
<div class="progress-bar"><div class="fill ${getProgressClass(q.percent)}" style="width:${q.percent}%"></div></div>
</li>
`).join('')}</ul>
`;
} else {
quotaHtml = `<ul class="quota-list">${quotas.map(q => `
<li class="quota-item">
<div class="label">${q.label}</div>
<div class="info-row">
<div class="percent">${q.percent}%</div>
<div class="reset">${formatResetTime(q.reset)}</div>
</div>
<div class="progress-bar"><div class="fill ${getProgressClass(q.percent)}" style="width:${q.percent}%"></div></div>
</li>
`).join('')}</ul>`;
}
}
return `
<div class="card ${provider}">
<div class="card-content">
<div class="card-header">
<span class="name" title="${item.name}">${email}</span>
</div>
<div class="card-body">${quotaHtml}</div>
</div>
</div>
`;
}).join('');
}
window.addEventListener('DOMContentLoaded', loadData);
</script>
</body>
</html>