-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
609 lines (523 loc) · 21.5 KB
/
index.html
File metadata and controls
609 lines (523 loc) · 21.5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Year Progress</title>
<meta name="description" content="Real-time year progress tracker.">
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<style>
:root {
/* --- 基础颜色 --- */
--bg-color: #0f172a;
--text-primary: #f8fafc;
--text-secondary: #64748b;
--track-bg: rgba(255, 255, 255, 0.06);
--icon-color: #94a3b8;
--icon-hover: #f8fafc;
/* --- 动态进度条颜色 --- */
--gradient-start: #38bdf8;
--gradient-end: #22d3ee;
}
[data-theme="light"] {
--bg-color: #f8fafc;
--text-primary: #0f172a;
--text-secondary: #94a3b8;
--track-bg: rgba(0, 0, 0, 0.06);
--icon-color: #64748b;
--icon-hover: #0f172a;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
-webkit-tap-highlight-color: transparent;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, monospace;
background-color: var(--bg-color);
color: var(--text-primary);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
overflow: hidden;
transition: background-color 0.5s ease, color 0.5s ease;
}
/*
Canvas 设置:
1. pointer-events: none -> 点击穿透,不影响操作页面
2. z-index: 50 -> 在文字之上,制造"微信烟花"的悬浮感
3. background: transparent -> 关键!背景完全透明
*/
#fireworks {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 50;
pointer-events: none;
background: transparent;
}
/* 工具栏 */
.toolbar {
position: fixed;
top: 2rem;
right: 2rem;
display: flex;
gap: 1.5rem;
z-index: 100;
opacity: 0.2;
transition: opacity 0.3s;
}
.toolbar:hover {
opacity: 1;
}
.btn-icon {
background: none;
border: none;
color: var(--icon-color);
cursor: pointer;
padding: 5px;
transition: transform 0.2s, color 0.2s;
}
.btn-icon:hover {
color: var(--icon-hover);
transform: scale(1.1);
}
.btn-icon svg {
width: 24px;
height: 24px;
fill: currentColor;
}
/* 主容器 */
.container {
width: 100%;
max-width: 680px;
padding: 2rem;
text-align: center;
position: relative;
z-index: 10;
}
h1 {
font-size: 4.5rem;
font-weight: 800;
margin: 0;
line-height: 1;
letter-spacing: -0.03em;
background: linear-gradient(135deg, var(--text-primary) 30%, var(--text-secondary) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
opacity: 0.95;
}
.year-label {
font-size: 0.85rem;
color: var(--text-secondary);
font-weight: 600;
letter-spacing: 0.4em;
text-transform: uppercase;
margin-top: 0.8rem;
margin-bottom: 3rem;
opacity: 0.8;
}
/* 进度条 */
.progress-wrapper {
position: relative;
margin-bottom: 2.5rem;
width: 100%;
padding: 10px 0;
}
.progress-track {
height: 3px;
background: var(--track-bg);
border-radius: 2px;
position: relative;
}
.progress-fill {
height: 100%;
width: 0%;
border-radius: 2px;
background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
background-size: 200% 100%;
animation: flow 2s linear infinite;
position: relative;
transition: width 0.2s linear;
}
.progress-head {
position: absolute;
right: -2px;
top: 50%;
transform: translateY(-50%);
width: 8px;
height: 8px;
background: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 0 10px var(--gradient-end), 0 0 20px var(--gradient-end);
z-index: 2;
transition: all 0.3s ease;
}
.progress-head.is-festival {
background: transparent;
box-shadow: none;
width: auto;
height: auto;
font-size: 24px;
right: -10px;
text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
@keyframes flow {
0% {
background-position: 100% 0;
}
100% {
background-position: 0 0;
}
}
.percentage-text {
font-size: 3.2rem;
font-weight: 700;
margin-top: 1rem;
font-variant-numeric: tabular-nums;
letter-spacing: -0.02em;
color: var(--text-primary);
}
.stats-grid {
display: flex;
justify-content: space-between;
margin-top: 3.5rem;
border-top: 1px solid var(--track-bg);
padding-top: 1.5rem;
}
.stat-item {
text-align: left;
min-width: 90px;
}
.stat-item:last-child {
text-align: right;
}
.stat-item.center {
text-align: center;
flex-grow: 1;
}
.stat-label {
font-size: 0.65rem;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.1em;
margin-bottom: 0.4rem;
font-weight: 600;
}
.stat-value {
font-family: 'Courier New', monospace;
font-size: 0.95rem;
font-weight: 600;
letter-spacing: -0.5px;
opacity: 0.9;
}
.quote {
margin-top: 3rem;
font-size: 0.85rem;
color: var(--text-secondary);
opacity: 0.8;
font-style: italic;
min-height: 1.5em;
transition: color 0.3s;
}
@media (max-width: 600px) {
h1 {
font-size: 3.5rem;
}
.year-label {
font-size: 0.8rem;
margin-bottom: 2.5rem;
}
.percentage-text {
font-size: 2.5rem;
}
.stats-grid {
flex-direction: column;
gap: 1rem;
text-align: center;
}
.stat-item,
.stat-item:last-child {
text-align: center;
}
.toolbar {
top: 1rem;
right: 1rem;
opacity: 1;
}
}
</style>
</head>
<body>
<canvas id="fireworks"></canvas>
<div class="toolbar">
<a href="https://github.com/LandonLi/YearProgress" target="_blank" class="btn-icon"
aria-label="GitHub Repository">
<svg viewBox="0 0 24 24">
<path
d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" />
</svg>
</a>
<button class="btn-icon" id="themeToggle" aria-label="Toggle Theme"></button>
<button class="btn-icon" id="fullscreenToggle" aria-label="Toggle Fullscreen">
<svg viewBox="0 0 24 24">
<path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" />
</svg>
</button>
</div>
<div class="container">
<h1 id="yearDisplay">----</h1>
<div class="year-label">Year Progress</div>
<div class="progress-wrapper">
<div class="progress-track">
<div class="progress-fill" id="progressBar">
<div id="progressHead" class="progress-head"></div>
</div>
</div>
<div class="percentage-text" id="percentageDisplay">--%</div>
</div>
<div class="stats-grid">
<div class="stat-item">
<div class="stat-label">Days Passed</div>
<div class="stat-value" id="daysPassed">--</div>
</div>
<div class="stat-item center">
<div class="stat-label">Current Time</div>
<div class="stat-value" id="currentTime">--</div>
</div>
<div class="stat-item">
<div class="stat-label">Days Left</div>
<div class="stat-value" id="daysLeft">--</div>
</div>
</div>
<div class="quote" id="quote"></div>
</div>
<script src="config.js"></script>
<script>
// --- 1. 真实烟花系统 (Realistic Fireworks) ---
class RealisticFireworks {
constructor() {
this.canvas = document.getElementById('fireworks');
this.ctx = this.canvas.getContext('2d');
this.particles = [];
this.isRunning = false;
this.resize();
window.addEventListener('resize', () => this.resize());
}
resize() {
this.canvas.width = window.innerWidth;
this.canvas.height = window.innerHeight;
}
createExplosion(x, y) {
const particleCount = 150;
// 真实烟花颜色:红、金、亮绿、电光蓝、紫
const colors = ['#ff0040', '#ffeb3b', '#00ff00', '#00ccff', '#ff00ff', '#ffffff'];
for (let i = 0; i < particleCount; i++) {
const angle = Math.random() * Math.PI * 2;
// 速度随机,模拟爆炸的不规则性
const speed = Math.random() * 6 + 2;
this.particles.push({
x: x, y: y,
vx: Math.cos(angle) * speed,
vy: Math.sin(angle) * speed,
life: 1.0,
decay: Math.random() * 0.015 + 0.005, // 消失速度
color: colors[Math.floor(Math.random() * colors.length)],
size: Math.random() * 2 + 1,
gravity: 0.05 // 重力下坠感
});
}
}
animate() {
if (!this.isRunning && this.particles.length === 0) {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
return;
}
// 核心逻辑:使用 destination-out 让上一帧变透明,而不是涂黑
// 这实现了"拖尾"效果,同时保证背景完全透明,不遮挡文字
this.ctx.globalCompositeOperation = 'destination-out';
this.ctx.fillStyle = 'rgba(0, 0, 0, 0.1)'; // 0.1 的透明度擦除,保留一点点拖尾
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
// 切换回绘图模式
this.ctx.globalCompositeOperation = 'lighter'; // 高光叠加,让重叠的烟花更亮
for (let i = this.particles.length - 1; i >= 0; i--) {
let p = this.particles[i];
p.x += p.vx;
p.y += p.vy;
p.vx *= 0.96; // 空气阻力
p.vy *= 0.96;
p.vy += p.gravity; // 施加重力,粒子会下坠
p.life -= p.decay;
if (p.life <= 0) {
this.particles.splice(i, 1);
} else {
this.ctx.fillStyle = p.color;
this.ctx.globalAlpha = p.life;
this.ctx.beginPath();
this.ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
this.ctx.fill();
}
}
if (this.isRunning && Math.random() < 0.05) { // 随机发射频率
// 在屏幕上半部分随机爆炸
this.createExplosion(
Math.random() * this.canvas.width,
Math.random() * this.canvas.height * 0.6
);
}
requestAnimationFrame(() => this.animate());
}
start() {
if (!this.isRunning) {
this.isRunning = true;
this.animate();
}
}
stop() {
this.isRunning = false;
}
}
const fireworks = new RealisticFireworks();
// --- 2. 基础功能 (Theme & Fullscreen) ---
const themeBtn = document.getElementById('themeToggle');
const root = document.documentElement;
const iconSun = '<svg viewBox="0 0 24 24"><path d="M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zM2 13h2c.55 0 1-.45 1-1s-.45-1-1-1H2c-.55 0-1 .45-1 1s.45 1 1 1zm18 0h2c.55 0 1-.45 1-1s-.45-1-1-1h-2c-.55 0-1 .45-1 1s.45 1 1 1zM11 2v2c0 .55.45 1 1 1s1-.45 1-1V2c0-.55-.45-1-1-1s-1 .45-1 1zm0 18v2c0 .55.45 1 1 1s1-.45 1-1v-2c0-.55-.45-1-1-1s-1 .45-1 1zM5.99 4.58c-.39-.39-1.03-.39-1.41 0-.39.39-.39 1.03 0 1.41l1.06 1.06c.39.39 1.03.39 1.41 0s.39-1.03 0-1.41L5.99 4.58zm12.37 12.37c-.39-.39-1.03-.39-1.41 0-.39.39-.39 1.03 0 1.41l1.06 1.06c.39.39 1.03.39 1.41 0 .39-.39.39-1.03 0-1.41l-1.06-1.06zm1.06-10.96c.39-.39.39-1.03 0-1.41-.39-.39-1.03-.39-1.41 0l-1.06 1.06c-.39.39-.39 1.03 0 1.41s1.03.39 1.41 0l1.06-1.06zM7.05 18.36c.39-.39.39-1.03 0-1.41-.39-.39-1.03-.39-1.41 0l-1.06 1.06c-.39.39-.39 1.03 0 1.41s1.03.39 1.41 0l1.06-1.06z"/></svg>';
const iconMoon = '<svg viewBox="0 0 24 24"><path d="M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9 9-4.03 9-9c0-.46-.04-.92-.1-1.36-.98 1.37-2.58 2.26-4.4 2.26-2.98 0-5.4-2.42-5.4-5.4 0-1.81.89-3.42 2.26-4.4-.44-.06-.9-.1-1.36-.1z"/></svg>';
let currentMode = 'dark';
function applyTheme(mode) {
currentMode = mode;
if (mode === 'light') {
root.setAttribute('data-theme', 'light');
themeBtn.innerHTML = iconMoon; themeBtn.setAttribute('aria-label', 'Switch to Dark Mode');
} else {
root.removeAttribute('data-theme'); themeBtn.innerHTML = iconSun; themeBtn.setAttribute('aria-label', 'Switch to Light Mode');
}
localStorage.setItem('theme', mode);
}
function initTheme() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme) applyTheme(savedTheme);
else applyTheme(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
}
themeBtn.addEventListener('click', () => applyTheme(currentMode === 'dark' ? 'light' : 'dark'));
initTheme();
const fullscreenBtn = document.getElementById('fullscreenToggle');
const ua = window.navigator.userAgent;
const isIOS = /iPad|iPhone|iPod/.test(ua) || (window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1);
if (isIOS) {
fullscreenBtn.style.display = 'none';
} else {
fullscreenBtn.addEventListener('click', () => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch(e => console.log(e));
} else if (document.exitFullscreen) {
document.exitFullscreen();
}
});
}
// --- 3. 核心业务逻辑 ---
const ui = {
bar: document.getElementById('progressBar'),
pct: document.getElementById('percentageDisplay'),
time: document.getElementById('currentTime'),
passed: document.getElementById('daysPassed'),
left: document.getElementById('daysLeft'),
year: document.getElementById('yearDisplay'),
quote: document.getElementById('quote'),
head: document.getElementById('progressHead')
};
const quotes = [
"Time flies like an arrow.", "Lost time is never found again.",
"The future is created now.", "Keep moving forward.", "Make it count."
];
ui.quote.innerText = quotes[new Date().getDay() % quotes.length];
let celebrating = false;
let lastKnownYear = new Date().getFullYear();
const pad = (n) => n.toString().padStart(2, '0');
// 调试彩蛋
window.triggerFireworks = () => {
if (celebrating) return;
console.log("Celebration triggered!");
startCelebration("HAPPY NEW YEAR!", true);
};
function startCelebration(message, isManual = false) {
celebrating = true;
fireworks.start();
ui.quote.innerText = message;
ui.quote.style.color = "#fb7185"; // 换成喜庆的红色系
ui.quote.style.fontWeight = "bold";
// 15秒后停止生成新烟花,旧烟花会自然落下消失
setTimeout(() => {
celebrating = false;
fireworks.stop();
if (!isManual) ui.quote.innerText = quotes[0];
ui.quote.style.color = "";
ui.quote.style.fontWeight = "";
}, 10000);
}
function update() {
const now = new Date();
const currentYear = now.getFullYear();
// 跨年自动检测
if (currentYear > lastKnownYear) {
lastKnownYear = currentYear;
startCelebration(`HAPPY NEW YEAR ${currentYear}!`);
}
const start = new Date(currentYear, 0, 1);
const end = new Date(currentYear + 1, 0, 1);
const total = end - start;
const elapsed = now - start;
let pct = (elapsed / total) * 100;
// 颜色逻辑
let colors = {};
if (pct < 50) {
colors = { start: '#38bdf8', end: '#22d3ee' }; // Cyan
} else if (pct < 90) {
colors = { start: '#818cf8', end: '#a78bfa' }; // Purple
} else {
colors = { start: '#fb7185', end: '#f43f5e' }; // Red
}
root.style.setProperty('--gradient-start', colors.start);
root.style.setProperty('--gradient-end', colors.end);
ui.year.innerText = currentYear;
ui.bar.style.width = `${pct.toFixed(4)}%`;
ui.pct.innerText = `${pct.toFixed(6)}%`;
// Festival Icon Logic
const todayKey = `${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
const festival = window.YearProgressConfig && window.YearProgressConfig.festivals && window.YearProgressConfig.festivals[todayKey];
if (festival && festival.icon) {
if (ui.head.innerText !== festival.icon) {
ui.head.innerText = festival.icon;
ui.head.classList.add('is-festival');
ui.head.title = festival.name || '';
}
} else {
if (ui.head.innerText !== '') {
ui.head.innerText = '';
ui.head.classList.remove('is-festival');
ui.head.removeAttribute('title');
}
}
const timeStr = `${currentYear}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
ui.time.innerText = timeStr;
const oneDay = 86400000;
ui.passed.innerText = (elapsed / oneDay).toFixed(1);
ui.left.innerText = ((total - elapsed) / oneDay).toFixed(1);
requestAnimationFrame(update);
}
requestAnimationFrame(update);
</script>
</body>
</html>