-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathtools-rank.html
More file actions
344 lines (301 loc) · 9.92 KB
/
tools-rank.html
File metadata and controls
344 lines (301 loc) · 9.92 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<link rel="icon" href="favicon.svg">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>工具使用排行 - JustHTMLs</title>
<link rel="canonical" href="https://www.htmls.dev/tools-rank.html">
<link rel="stylesheet" href="assets/vendor/fontawesome/css/all.min.css">
<style>
:root {
--primary: #6366f1;
--secondary: #14b8a6;
--bg: #0f172a;
--bg-card: #1e293b;
--bg-hover: #334155;
--text: #f1f5f9;
--text-muted: #94a3b8;
--border: #334155;
--shadow: 0 10px 25px rgba(15, 23, 42, 0.35);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: radial-gradient(circle at top, rgba(99, 102, 241, 0.2), transparent 55%), var(--bg);
color: var(--text);
min-height: 100vh;
}
.container {
max-width: 1100px;
margin: 0 auto;
padding: 0 20px;
}
header {
background: rgba(15, 23, 42, 0.9);
border-bottom: 1px solid var(--border);
padding: 16px 0;
position: sticky;
top: 0;
z-index: 10;
backdrop-filter: blur(10px);
}
.header-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
flex-wrap: wrap;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 8px;
color: var(--text-muted);
text-decoration: none;
font-size: 14px;
transition: color 0.2s;
}
.back-link:hover {
color: var(--primary);
}
.page-title {
font-size: 24px;
font-weight: 700;
}
.hero {
padding: 40px 0 20px;
}
.hero p {
color: var(--text-muted);
margin-top: 8px;
}
.panel {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 16px;
padding: 24px;
box-shadow: var(--shadow);
margin-bottom: 24px;
}
.controls {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.controls label {
font-size: 14px;
color: var(--text-muted);
}
.controls select {
padding: 8px 12px;
border-radius: 10px;
border: 1px solid var(--border);
background: var(--bg);
color: var(--text);
font-size: 14px;
}
.rank-list {
display: grid;
gap: 12px;
}
.rank-item {
display: grid;
grid-template-columns: 56px 1fr auto;
gap: 16px;
align-items: center;
padding: 14px 16px;
border-radius: 14px;
border: 1px solid var(--border);
background: rgba(30, 41, 59, 0.8);
transition: transform 0.2s, border-color 0.2s;
}
.rank-item:hover {
transform: translateY(-2px);
border-color: rgba(99, 102, 241, 0.6);
}
.rank-badge {
width: 40px;
height: 40px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
background: rgba(99, 102, 241, 0.2);
color: var(--primary);
}
.rank-info {
display: flex;
flex-direction: column;
gap: 4px;
}
.rank-name {
font-size: 16px;
font-weight: 600;
color: var(--text);
text-decoration: none;
}
.rank-meta {
font-size: 13px;
color: var(--text-muted);
}
.rank-metric {
text-align: right;
}
.metric-value {
font-size: 18px;
font-weight: 700;
}
.metric-label {
font-size: 12px;
color: var(--text-muted);
}
.loading {
text-align: center;
padding: 40px 0;
color: var(--text-muted);
}
.empty-state {
text-align: center;
padding: 30px 0;
color: var(--text-muted);
}
@media (max-width: 720px) {
.rank-item {
grid-template-columns: 48px 1fr;
grid-template-rows: auto auto;
}
.rank-metric {
grid-column: 1 / -1;
text-align: left;
padding-left: 64px;
}
}
</style>
</head>
<body>
<header>
<div class="container">
<div class="header-row">
<a class="back-link" href="./"><i class="fas fa-arrow-left"></i> 返回首页</a>
<div class="page-title">工具使用排行</div>
<div class="controls">
<label for="rank-metric">排行指标</label>
<select id="rank-metric">
<option value="pv-total">总 PV</option>
<option value="uv-total">总 UV</option>
<option value="pv-day">今日 PV</option>
<option value="uv-day">今日 UV</option>
</select>
</div>
</div>
</div>
</header>
<main>
<section class="hero">
<div class="container">
<h1>工具使用排行</h1>
<p>基于 PV/UV 统计,展示热门工具的整体使用情况。</p>
</div>
</section>
<section class="container">
<div class="panel">
<div id="rank-list" class="rank-list">
<div class="loading"><i class="fas fa-spinner fa-spin"></i> 正在加载排行数据...</div>
</div>
</div>
</section>
</main>
<script>
let tools = [];
let stats = {};
async function loadTools() {
const response = await fetch('index.json');
if (!response.ok) {
throw new Error('加载工具列表失败');
}
const data = await response.json();
tools = data.tools || [];
}
async function loadStats() {
if (tools.length === 0) return;
const ids = tools.map(tool => tool.id).join(',');
const response = await fetch(`api/clicks?ids=${encodeURIComponent(ids)}`);
if (!response.ok) {
throw new Error('加载统计失败');
}
const data = await response.json();
stats = data.counts || {};
}
function getMetricValue(stat, metric) {
if (!stat) return 0;
if (metric === 'pv-total') return stat.pv?.total || 0;
if (metric === 'uv-total') return stat.uv?.total || 0;
if (metric === 'pv-day') return stat.pv?.day || 0;
if (metric === 'uv-day') return stat.uv?.day || 0;
return 0;
}
function getMetricLabel(metric) {
if (metric === 'pv-total') return '总 PV';
if (metric === 'uv-total') return '总 UV';
if (metric === 'pv-day') return '今日 PV';
if (metric === 'uv-day') return '今日 UV';
return '';
}
function formatNumber(value) {
if (typeof value !== 'number') return '--';
return value.toLocaleString('zh-CN');
}
function renderRankList(metric) {
const container = document.getElementById('rank-list');
const list = tools
.map(tool => ({
tool,
stat: stats[tool.id],
metricValue: getMetricValue(stats[tool.id], metric)
}))
.sort((a, b) => b.metricValue - a.metricValue);
if (list.length === 0) {
container.innerHTML = '<div class="empty-state">暂无排行数据</div>';
return;
}
const label = getMetricLabel(metric);
container.innerHTML = list.map((item, index) => {
return `
<div class="rank-item">
<div class="rank-badge">${index + 1}</div>
<div class="rank-info">
<a class="rank-name" href="${item.tool.entry}">${item.tool.name}</a>
<div class="rank-meta">${item.tool.description}</div>
</div>
<div class="rank-metric">
<div class="metric-value">${formatNumber(item.metricValue)}</div>
<div class="metric-label">${label}</div>
</div>
</div>
`;
}).join('');
}
async function init() {
try {
await loadTools();
await loadStats();
renderRankList(document.getElementById('rank-metric').value);
} catch (error) {
document.getElementById('rank-list').innerHTML = `<div class="empty-state">${error.message}</div>`;
}
}
document.getElementById('rank-metric').addEventListener('change', (event) => {
renderRankList(event.target.value);
});
init();
</script>
<script src="assets/clicks.js" defer></script>
</body>
</html>