-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
365 lines (323 loc) · 12.6 KB
/
index.html
File metadata and controls
365 lines (323 loc) · 12.6 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>📚 翻译 Wiki 列表</title>
<style>
:root {
--primary-color: #3b82f6; /* Slightly brighter blue */
--primary-color-dark: #2563eb;
--hover-color: #1d4ed8;
--background: #f7fafc; /* Slightly off-white */
--card-background: #ffffff;
--text-primary: #1f2937; /* Darker gray */
--text-secondary: #6b7280; /* Medium gray */
--border-color: #e5e7eb; /* Light gray */
--shadow-color: rgba(0, 0, 0, 0.05);
--shadow-color-hover: rgba(0, 0, 0, 0.1);
--focus-ring-color: rgba(59, 130, 246, 0.3);
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
max-width: 800px;
margin: 30px auto; /* Increased margin */
padding: 0 20px;
background-color: var(--background);
color: var(--text-primary);
line-height: 1.6;
}
h1 {
text-align: center;
color: var(--text-primary);
margin-bottom: 2rem;
font-weight: 700;
}
.search-container {
position: relative;
margin-bottom: 2.5rem; /* Increased spacing */
}
#searchInput {
width: 100%;
padding: 14px 50px 14px 20px; /* Adjusted padding for icon */
border: 1px solid var(--border-color);
border-radius: 50px;
font-size: 1rem;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
background-color: var(--card-background);
box-shadow: 0 2px 4px var(--shadow-color);
-webkit-appearance: none; /* Remove default iOS styling */
appearance: none;
}
#searchInput:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px var(--focus-ring-color), 0 2px 4px var(--shadow-color);
}
.search-icon {
position: absolute;
right: 18px; /* Adjusted position */
top: 50%;
transform: translateY(-50%);
color: var(--text-secondary);
pointer-events: none; /* Prevent icon from intercepting clicks */
width: 20px;
height: 20px;
}
#resultCount {
text-align: center;
margin-bottom: 1rem;
color: var(--text-secondary);
font-size: 0.9em;
}
.site-list {
list-style: none;
padding: 0;
}
.site-item {
background-color: var(--card-background);
border-radius: 12px; /* Slightly smaller radius */
padding: 20px 24px; /* Adjusted padding */
margin-bottom: 1rem; /* Consistent spacing */
box-shadow: 0 4px 6px -1px var(--shadow-color);
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px; /* Gap between flex items */
transition: transform 0.2s ease, box-shadow 0.2s ease;
border: 1px solid var(--border-color); /* Subtle border */
}
.site-item:hover {
transform: translateY(-3px);
box-shadow: 0 6px 12px -2px var(--shadow-color-hover);
}
.site-info {
display: flex;
align-items: center;
gap: 18px; /* Adjusted gap */
flex-grow: 1;
min-width: 0; /* Prevent flex item overflow */
}
.site-image {
width: 52px; /* Slightly larger */
height: 52px;
border-radius: 10px; /* Adjusted radius */
object-fit: cover;
background-color: #f1f5f9; /* Placeholder background */
flex-shrink: 0; /* Prevent image shrinking */
border: 1px solid var(--border-color);
}
.site-details {
flex: 1;
min-width: 0; /* Allow text to wrap */
}
.site-title {
font-weight: 600;
color: var(--text-primary);
margin: 0 0 4px;
font-size: 1.05em; /* Slightly larger title */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis; /* Add ellipsis if title too long */
}
.site-meta {
font-size: 0.88em; /* Slightly adjusted size */
color: var(--text-secondary);
line-height: 1.5; /* Adjusted line height */
}
.visit-button {
background: linear-gradient(135deg, var(--primary-color), var(--primary-color-dark));
color: white;
padding: 10px 20px; /* Adjusted padding */
border-radius: 8px;
text-decoration: none;
font-weight: 500;
transition: all 0.2s ease;
display: inline-flex;
align-items: center;
gap: 8px; /* Gap for icon */
white-space: nowrap; /* Prevent button text wrapping */
flex-shrink: 0; /* Prevent button shrinking */
box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}
.visit-button:hover {
transform: scale(1.03); /* Slightly less intense scale */
box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
}
.visit-button:focus {
outline: none;
box-shadow: 0 0 0 3px var(--focus-ring-color), 0 4px 8px rgba(59, 130, 246, 0.3);
}
.visit-button svg {
width: 16px;
height: 16px;
}
.message-box { /* Common style for loading/no-results */
text-align: center;
padding: 50px 20px;
color: var(--text-secondary);
font-size: 1.1em;
border: 1px dashed var(--border-color);
border-radius: 12px;
background-color: var(--card-background);
}
.loading-spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: var(--primary-color);
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 15px auto; /* Center spinner */
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 640px) {
body {
margin: 20px auto;
}
h1 {
font-size: 1.5em;
}
.site-item {
flex-direction: column;
align-items: stretch; /* Stretch items full width */
padding: 16px;
}
.site-info {
gap: 12px;
}
.site-title {
white-space: normal; /* Allow wrapping on mobile */
overflow: visible;
text-overflow: clip;
}
.visit-button {
width: 100%;
justify-content: center;
padding: 12px 24px; /* Larger tap target */
}
.search-container {
margin-bottom: 1.5rem;
}
#resultCount {
margin-bottom: 0.5rem;
}
}
</style>
</head>
<body>
<h1>📚 翻译 Wiki 列表</h1>
<div class="search-container">
<input type="text" id="searchInput" placeholder="搜索书名、备注或翻译者..." aria-label="搜索 Wiki">
<div class="search-icon">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
</svg>
</div>
</div>
<div id="resultCount"></div>
<ul class="site-list" id="siteList">
<div class="message-box loading">
<div class="loading-spinner"></div>
加载中...
</div>
</ul>
<script>
let allData = []; // Store all fetched data
let searchTimeout = null; // Timeout ID for debouncing
// --- Utility Function ---
function debounce(func, delay) {
return function(...args) {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
// --- Core Functions ---
async function init() {
const listContainer = document.getElementById('siteList');
try {
const response = await fetch('https://bookshelf.8aka.org/bookshelf.json');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
allData = await response.json();
renderList(allData); // Initial render with all data
setupSearch();
} catch (error) {
console.error('获取数据失败:', error);
listContainer.innerHTML = `
<div class="message-box no-results">
<p>😕 数据加载失败</p>
<p>请检查网络连接或稍后刷新重试。</p>
</div>`;
// Clear result count on error
document.getElementById('resultCount').textContent = '';
}
}
function renderList(data) {
const listContainer = document.getElementById('siteList');
const resultCountContainer = document.getElementById('resultCount');
listContainer.innerHTML = ''; // Clear previous results or loading state
if (data.length === 0) {
listContainer.innerHTML = `
<div class="message-box no-results">
<p>🤷♀️ 未找到匹配的结果</p>
<p>请尝试不同的关键词。</p>
</div>`;
resultCountContainer.textContent = '未找到结果';
return;
}
// Update result count
resultCountContainer.textContent = `共找到 ${data.length} 个结果`;
data.forEach(item => {
const listItem = document.createElement('li');
listItem.className = 'site-item';
// Default image if item.image is missing or empty
const imageUrl = item.image || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; // Transparent pixel
listItem.innerHTML = `
<div class="site-info">
<img src="${imageUrl}" class="site-image" alt="${item.title || 'Wiki Cover'}" loading="lazy">
<div class="site-details">
<h3 class="site-title">${item.title || '未知标题'}</h3>
<div class="site-meta">
${item.note ? `<span>📝 ${item.note}</span><br>` : ''}
翻译者:${item.translator === 'unknown' || !item.translator ? '未知' : item.translator}
</div>
</div>
</div>
<a href="${item.url}" target="_blank" rel="noopener noreferrer" class="visit-button">
访问网站
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5 21 12m0 0-7.5 7.5M21 12H3" />
</svg>
</a>
`;
listContainer.appendChild(listItem);
});
}
function setupSearch() {
const searchInput = document.getElementById('searchInput');
// Debounced search handler
const handleSearch = debounce((event) => {
const keyword = event.target.value.toLowerCase().trim();
const filteredData = allData.filter(item => {
const titleMatch = item.title && item.title.toLowerCase().includes(keyword);
const noteMatch = item.note && item.note.toLowerCase().includes(keyword);
const translatorMatch = item.translator && item.translator.toLowerCase().includes(keyword);
return titleMatch || noteMatch || translatorMatch;
});
renderList(filteredData);
}, 300); // 300ms delay
searchInput.addEventListener('input', handleSearch);
}
// --- Initialize ---
document.addEventListener('DOMContentLoaded', init);
</script>
</body>
</html>