-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi-data-viewer.html
More file actions
288 lines (273 loc) · 8.09 KB
/
api-data-viewer.html
File metadata and controls
288 lines (273 loc) · 8.09 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API 数据查看器 - FunWebGames</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
header {
text-align: center;
color: white;
margin-bottom: 30px;
}
header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
header p {
opacity: 0.9;
font-size: 1.1em;
}
.data-selector {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-bottom: 20px;
justify-content: center;
}
.data-selector button {
padding: 12px 24px;
border: none;
border-radius: 8px;
background: white;
color: #667eea;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
}
.data-selector button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
.data-selector button.active {
background: #764ba2;
color: white;
}
.data-card {
background: white;
border-radius: 12px;
padding: 25px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.data-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 2px solid #f0f0f0;
}
.data-header h2 {
color: #333;
}
.data-stats {
display: flex;
gap: 20px;
}
.stat {
text-align: center;
}
.stat-value {
font-size: 1.5em;
font-weight: bold;
color: #667eea;
}
.stat-label {
font-size: 0.9em;
color: #666;
}
.data-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 15px;
}
.item-card {
background: #f8f9fa;
border-radius: 8px;
padding: 15px;
border-left: 4px solid #667eea;
}
.item-card h3 {
color: #333;
margin-bottom: 8px;
}
.item-card p {
color: #666;
font-size: 0.9em;
margin: 5px 0;
}
.price {
font-size: 1.3em;
font-weight: bold;
color: #27ae60;
}
.price.down {
color: #e74c3c;
}
.refresh-btn {
background: #667eea;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
}
.refresh-btn:hover {
background: #764ba2;
}
.loading {
text-align: center;
padding: 40px;
color: white;
font-size: 1.2em;
}
.error {
background: #e74c3c;
color: white;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>🔄 API 数据查看器</h1>
<p>FunWebGames 外部 API 同步数据展示</p>
</header>
<div class="data-selector" id="dataSelector">
<button data-file="crypto-prices.json" class="active">💰 加密货币价格</button>
<button data-file="github-repos.json">📦 GitHub 仓库</button>
<button data-file="scores.json">🎮 游戏分数</button>
<button data-file="users.json">👥 用户数据</button>
</div>
<div class="data-card">
<div class="data-header">
<h2 id="dataTitle">加密货币价格</h2>
<div class="data-stats">
<div class="stat">
<div class="stat-value" id="recordCount">-</div>
<div class="stat-label">记录数</div>
</div>
<div class="stat">
<div class="stat-value" id="fileSize">-</div>
<div class="stat-label">文件大小</div>
</div>
</div>
<button class="refresh-btn" onclick="loadCurrentData()">🔄 刷新</button>
</div>
<div id="dataContent" class="data-grid">
<div class="loading">加载中...</div>
</div>
</div>
</div>
<script>
let currentFile = 'crypto-prices.json';
// 初始化
document.querySelectorAll('#dataSelector button').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('#dataSelector button').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
currentFile = btn.dataset.file;
loadCurrentData();
});
});
async function loadCurrentData() {
const contentDiv = document.getElementById('dataContent');
const titleEl = document.getElementById('dataTitle');
const countEl = document.getElementById('recordCount');
const sizeEl = document.getElementById('fileSize');
contentDiv.innerHTML = '<div class="loading">🔄 加载数据中...</div>';
try {
const response = await fetch(`data/${currentFile}`);
if (!response.ok) throw new Error('文件不存在');
const data = await response.json();
// 更新统计
const count = Array.isArray(data) ? data.length : 1;
countEl.textContent = count;
// 根据文件类型渲染
if (currentFile === 'crypto-prices.json') {
titleEl.textContent = '💰 加密货币价格 (USD)';
renderCrypto(data);
} else if (currentFile === 'github-repos.json') {
titleEl.textContent = '📦 GitHub 仓库';
renderGitHub(data);
} else if (currentFile === 'scores.json') {
titleEl.textContent = '🎮 游戏分数';
renderScores(data);
} else if (currentFile === 'users.json') {
titleEl.textContent = '👥 用户数据';
renderUsers(data);
}
} catch (error) {
contentDiv.innerHTML = `<div class="error">❌ 加载失败:${error.message}</div>`;
}
}
function renderCrypto(data) {
const contentDiv = document.getElementById('dataContent');
contentDiv.innerHTML = data.map(coin => `
<div class="item-card">
<h3>${coin.name} (${coin.symbol.toUpperCase()})</h3>
<p class="price ${coin.price_change_percentage_24h >= 0 ? '' : 'down'}">
$${coin.current_price.toLocaleString()}
</p>
<p>排名:#${coin.market_cap_rank}</p>
<p>24h 变化:${coin.price_change_percentage_24h.toFixed(2)}%</p>
<p>市值:$${(coin.market_cap / 1e9).toFixed(2)}B</p>
</div>
`).join('');
}
function renderGitHub(data) {
const contentDiv = document.getElementById('dataContent');
const repos = Array.isArray(data) ? data : [data];
contentDiv.innerHTML = repos.map(repo => `
<div class="item-card">
<h3>${repo.name}</h3>
<p>${repo.description || '无描述'}</p>
<p>⭐ ${repo.stargazers_count} | 🍴 ${repo.forks_count}</p>
<p>📅 更新:${new Date(repo.updated_at).toLocaleDateString()}</p>
<p><a href="${repo.html_url}" target="_blank">查看仓库 →</a></p>
</div>
`).join('');
}
function renderScores(data) {
const contentDiv = document.getElementById('dataContent');
const scores = Array.isArray(data) ? data.slice(0, 20) : [data];
contentDiv.innerHTML = scores.map((item, i) => `
<div class="item-card">
<h3>#${i + 1} ${item.title || '记录'}</h3>
<p>ID: ${item.id}</p>
<p>用户:${item.userId}</p>
</div>
`).join('');
}
function renderUsers(data) {
const contentDiv = document.getElementById('dataContent');
const users = Array.isArray(data) ? data : [data];
contentDiv.innerHTML = users.map(user => `
<div class="item-card">
<h3>${user.name}</h3>
<p>📧 ${user.email}</p>
<p>🏢 ${user.company}</p>
<p>🌐 ${user.website}</p>
</div>
`).join('');
}
// 初始加载
loadCurrentData();
</script>
</body>
</html>