-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathworker.js
More file actions
1596 lines (1388 loc) · 59.5 KB
/
worker.js
File metadata and controls
1596 lines (1388 loc) · 59.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
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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* CF-Proxy: 通用代理服务,基于 Cloudflare Workers 实现的无服务器代理加速解决方案,支持访问被墙或受限的 URL。
* Repo: https://github.com/sinspired/CF-Proxy
*/
const REPO_URL = "https://github.com/sinspired/CF-Proxy";
const RAW_URL = "https://raw.githubusercontent.com/sinspired/CF-Proxy/main";
const SITE_NAME = "CF Proxy - 通用代理加速";
// 需要注入 GitHub Token 的主机列表
const GITHUB_HOSTS = ['api.github.com', 'uploads.github.com'];
// 需要手动处理的重定向状态码
const REDIRECT_CODES = new Set([301, 302, 303, 307, 308]);
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
// HTML 节点重写器,用于将页面内的相对链接改为代理链接
class DOMRewriter {
constructor(proxyOrigin, targetBaseUrl) {
this.proxyOrigin = proxyOrigin;
this.targetBaseUrl = targetBaseUrl;
}
rewrite(element, attr) {
const val = element.getAttribute(attr);
// 忽略空值、锚点、JS脚本和 Base64 图片
if (!val || val.startsWith('javascript:') || val.startsWith('mailto:') || val.startsWith('data:') || val.startsWith('#')) return;
try {
// 将相对路径解析为目标域的绝对路径 (如 /index.php -> https://xyy.com/index.php)
const absUrl = new URL(val, this.targetBaseUrl).toString();
// 拼上代理的前缀
element.setAttribute(attr, `${this.proxyOrigin}/${absUrl}`);
} catch (e) {
// 解析失败(比如存在语法错误的URL)则保持原样
}
}
element(element) {
if (element.tagName === 'a') this.rewrite(element, 'href');
if (element.tagName === 'img') this.rewrite(element, 'src');
if (element.tagName === 'link') this.rewrite(element, 'href');
if (element.tagName === 'script') this.rewrite(element, 'src');
if (element.tagName === 'form') this.rewrite(element, 'action');
if (element.tagName === 'iframe') this.rewrite(element, 'src');
}
}
async function handleRequest(request) {
const url = new URL(request.url);
// 1. 根目录与静态资源
if (url.pathname === "/") {
return new Response(getHtml(url.host), { headers: { 'Content-Type': 'text/html; charset=utf-8' } });
}
if (url.pathname === '/favicon.ico' || url.pathname === '/favicon.svg') {
return new Response(getLogoSvg(), { headers: { 'Content-Type': 'image/svg+xml' } });
}
if (url.pathname === '/preview.png') {
return fetch(`${RAW_URL}/preview.png`);
}
if (url.pathname === '/CF-Proxy_OG.png') {
return fetch(`${RAW_URL}/CF-Proxy_OG.png`);
}
// 2. 内部 API: 纯 Server-Side 网络连通性验证
if (url.pathname === '/__proxy_check') {
const domain = url.searchParams.get('domain');
if (!domain) return new Response(JSON.stringify({ Status: -1, msg: 'Missing domain' }), { status: 400 });
try {
const hostname = domain.split(':')[0];
const dnsHeaders = { 'accept': 'application/dns-json' };
const [ipv4Resp, ipv6Resp] = await Promise.all([
fetch(`https://cloudflare-dns.com/dns-query?name=${hostname}&type=A`, { headers: dnsHeaders }),
fetch(`https://cloudflare-dns.com/dns-query?name=${hostname}&type=AAAA`, { headers: dnsHeaders })
]);
const [ipv4, ipv6] = await Promise.all([ipv4Resp.json(), ipv6Resp.json()]);
const hasIpv4 = ipv4.Status === 0 && ipv4.Answer && ipv4.Answer.length > 0;
const hasIpv6 = ipv6.Status === 0 && ipv6.Answer && ipv6.Answer.length > 0;
const status = (hasIpv4 || hasIpv6) ? 0 : 3;
return new Response(JSON.stringify({ Status: status }), {
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }
});
} catch (e) {
return new Response(JSON.stringify({ Status: -1, error: e.message }), {
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }
});
}
}
// 测试 GitHub Token 配置状态
// if (url.pathname === '/__debug_gh') {
// const ghToken = getGhToken();
// const info = {
// token_configured: !!ghToken,
// // 只暴露前8位用于确认是正确的 Token,后面隐藏以防泄露
// token_prefix: ghToken ? ghToken.substring(0, 8) + '...' : null,
// };
// // 如果 token 存在,实际测一下 GitHub API 的剩余配额
// if (ghToken) {
// try {
// const resp = await fetch('https://api.github.com/rate_limit', {
// headers: {
// 'Authorization': `Bearer ${ghToken}`,
// 'User-Agent': 'CF-Proxy/Worker'
// }
// });
// const data = await resp.json();
// info.rate_limit = data.rate;
// } catch (e) {
// info.rate_limit_error = e.message;
// }
// }
// return new Response(JSON.stringify(info, null, 2), {
// headers: { 'Content-Type': 'application/json' }
// });
// }
// 3. 代理逻辑解析
let actualUrlStr = url.pathname.slice(1) + url.search;
// Referer 子路径补偿
// 用于修复页面内 JS 发起的相对路径 AJAX 请求,或 CSS 文件内未被 HTMLRewriter 拦截的相对资源
const referer = request.headers.get('Referer');
// 如果存在 Referer 且当前请求看起来像是一个相对路径资源 (没有 http 前缀)
if (referer && !actualUrlStr.startsWith('http')) {
try {
const refererUrl = new URL(referer);
// 只有当请求是由我们的代理服务发出的(且不在主页)
if (refererUrl.hostname === url.hostname && refererUrl.pathname.length > 1) {
let refTarget = refererUrl.pathname.slice(1);
if (!refTarget.startsWith('http')) {
if (refTarget.includes('.')) refTarget = 'https://' + refTarget;
}
const baseTargetUrl = new URL(refTarget);
// 把类似于 /index.php 组合拼装回真实域名的地址
const resolvedTarget = new URL(url.pathname + url.search, baseTargetUrl).toString();
// 自动纠正:302 重定向到正确的代理地址
return Response.redirect(`${url.origin}/${resolvedTarget}`, 302);
}
} catch (e) {
// 解析失败忽略,继续走原有流程
}
}
// 智能补全协议逻辑
if (!actualUrlStr.startsWith('http')) {
if (actualUrlStr.includes('.') && !actualUrlStr.startsWith('favicon')) {
actualUrlStr = 'https://' + actualUrlStr;
} else {
return new Response(getHtml(url.host), { headers: { 'Content-Type': 'text/html; charset=utf-8' } });
}
}
try {
const targetUrl = new URL(actualUrlStr);
// 构建请求头,添加必要的 Host、Referer、Origin 等字段
const newHeaders = new Headers(request.headers);
newHeaders.set('Host', targetUrl.host);
newHeaders.set('Referer', targetUrl.origin);
newHeaders.set('Origin', targetUrl.origin);
// 删除可能暴露用户真实 IP 的字段
['cf-connecting-ip', 'cf-ipcountry', 'x-forwarded-for', 'x-real-ip'].forEach(h => newHeaders.delete(h));
// GitHub Token 注入
if (GITHUB_HOSTS.includes(targetUrl.hostname)) {
// 使用 globalThis 安全访问 Workers 环境变量,避免 ReferenceError
const ghToken = getGhToken();
if (ghToken) {
newHeaders.set('Authorization', `Bearer ${ghToken}`);
console.log('[CF-Proxy] GitHub Token injected for:', targetUrl.hostname);
} else {
// Token 未配置或为空,记录警告(在 Workers Dashboard 日志可见)
console.warn('[CF-Proxy] GH_TOKEN is not set or empty, GitHub rate limit may apply.');
}
// GitHub API 要求必须有合法的 User-Agent
newHeaders.set('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36');
} else {
if (!newHeaders.get('User-Agent')) {
newHeaders.set('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36');
}
}
const response = await fetch(new Request(targetUrl.toString(), {
headers: newHeaders,
method: request.method,
body: request.body,
redirect: 'manual' // 手动处理重定向非常关键
}));
// 处理重定向,保持在代理路径下
if (REDIRECT_CODES.has(response.status)) {
const location = response.headers.get('location');
if (location) {
const redirectUrl = new URL(location, targetUrl).toString();
return Response.redirect(`${url.origin}/${redirectUrl}`, response.status);
}
}
const responseHeaders = new Headers(response.headers);
responseHeaders.set('Access-Control-Allow-Origin', '*');
responseHeaders.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
responseHeaders.set('Access-Control-Allow-Headers', '*');
responseHeaders.delete('Content-Security-Policy');
responseHeaders.delete('X-Frame-Options');
let finalResponse = new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: responseHeaders
});
// 实时重写 HTML 中的链接
const contentType = responseHeaders.get('Content-Type') || '';
if (contentType.toLowerCase().includes('text/html')) {
// 当内容是网页时,通过 HTMLRewriter 重写所有的资源链接和 a 标签,使之保持在代理下
finalResponse = new HTMLRewriter()
.on('a, img, link, script, form, iframe', new DOMRewriter(url.origin, targetUrl.toString()))
.transform(finalResponse);
}
return finalResponse;
} catch (e) {
return new Response(getErrorHtml(e.message, actualUrlStr), {
status: 500,
headers: { 'Content-Type': 'text/html; charset=utf-8' }
});
}
}
// 安全读取 GitHub Token 环境变量(避免 ReferenceError)
function getGhToken() {
return (typeof globalThis.GH_TOKEN === 'string' && globalThis.GH_TOKEN.trim())
? globalThis.GH_TOKEN.trim()
: null;
}
// favicon 使用简洁版本
function getLogoSvg() {
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#01af7b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>`;
}
function getErrorHtml(errorMsg, targetUrl) {
return `<!DOCTYPE html>
<html lang="zh-CN" id="htmlRoot">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>代理访问失败 - ${SITE_NAME}</title>
<style>
:root { --bg: #ffffff; --text: #111111; --text-light: #888888; --line: #eaeaea; --error: #ef4444; }
@media (prefers-color-scheme: dark) { :root { --bg: #0a0a0a; --text: #f0f0f0; --text-light: #666666; --line: rgba(255,255,255,0.15); } }
body { font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; margin: 0; padding: 20px; text-align: center; }
.icon { color: var(--error); width: 48px; height: 48px; margin-bottom: 20px; }
h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 12px; }
.url { color: var(--text-light); word-break: break-all; margin-bottom: 24px; font-family: ui-monospace, monospace; font-size: 0.95rem; }
.code { background: rgba(239, 68, 68, 0.08); color: var(--error); padding: 12px 20px; border-radius: 8px; font-family: ui-monospace, monospace; font-size: 0.85rem; margin-bottom: 40px; text-align: left; max-width: 100%; word-break: break-all; border: 1px solid rgba(239, 68, 68, 0.2); }
a { color: var(--text); text-decoration: none; border-bottom: 1px solid var(--line); padding-bottom: 2px; transition: opacity 0.2s; font-size: 0.95rem; }
a:hover { opacity: 0.6; }
</style>
</head>
<body>
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
<h1>无法访问目标地址</h1>
<div class="url">${targetUrl}</div>
<div class="code">Error: ${errorMsg}</div>
<a href="/">返回首页</a>
</body>
</html>`;
}
function getHtml(host) {
return `<!DOCTYPE html>
<html lang="zh-CN" id="htmlRoot">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="icon" href="/favicon.ico" type="image/svg+xml">
<title>${SITE_NAME}</title>
<meta name="description" content="基于 Cloudflare Workers 的极简通用代理加速服务。">
<!-- Open Graph -->
<meta property="og:title" content="${SITE_NAME}" />
<meta property="og:description" content="跨越边界,访问任意 URL。" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://${host}/" />
<meta property="og:image" content="https://${host}/CF-Proxy_OG.png" />
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="${SITE_NAME}" />
<meta name="twitter:description" content="跨越边界,访问任意 URL。" />
<meta name="twitter:image" content="https://${host}/CF-Proxy_OG.png" />
<!-- 主题初始化(防闪烁):优先 localStorage,其次系统偏好 -->
<script>(function () { var s = localStorage.getItem('cf-theme'); var dark = s === 'dark' || (s === null && window.matchMedia('(prefers-color-scheme:dark)').matches); if (dark) document.getElementById('htmlRoot').classList.add('dark'); })()</script>
<style>
:root {
--primary: #000000;
--primary-disabled: rgba(0, 0, 0, 0.3);
--bg: #ffffff;
--text: #111111;
--text-light: #888888;
--line: #c9c9c9;
--line-focus: rgba(33, 32, 32, 0.374);
--capsule-bg: rgba(0, 0, 0, 0.04);
--success: #10b981;
--error: #ef4444;
--warn: #f59e0b;
--orbit-glow: rgba(245, 158, 11, 0.10);
/* 太阳光晕色 */
}
html.dark {
--primary: #ffffff;
--primary-disabled: rgba(255, 255, 255, 0.25);
--bg: #0a0a0a;
--text: #f0f0f0;
--text-light: #666666;
--line: rgba(255, 255, 255, 0.20);
--line-focus: rgba(186, 208, 233, 0.6);
--capsule-bg: rgba(255, 255, 255, 0.08);
--orbit-glow: rgba(147, 197, 253, 0.16);
/* 月亮光晕色 */
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html {
height: 100%;
overflow-x: hidden;
}
body {
overflow-x: hidden;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg);
color: var(--text);
/* svh 在 Firefox Android 上比 dvh 更稳定,不会受输入法状态切换的干扰 */
height: 100svh;
display: flex;
flex-direction: column;
transition: background-color 0.8s ease, color 0.6s ease;
}
/* 星空背景(深色专用) */
#starField {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 0;
opacity: 0;
transition: opacity 1.2s ease;
}
html.dark #starField {
opacity: 0.6;
}
/* 主内容区 */
.main-container {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
max-width: 640px;
margin: 0 auto;
text-align: center;
padding: 20px 24px 80px;
animation: fadeIn 0.8s ease forwards;
position: relative;
z-index: 1;
}
h1 {
font-size: 2.4rem;
font-weight: 700;
margin-bottom: 0.5rem;
letter-spacing: -0.03em;
transition: font-size 0.3s ease;
}
.tagline {
color: var(--text-light);
font-size: 1.05rem;
margin-bottom: 4rem;
letter-spacing: -0.01em;
transition: color 0.6s ease, font-size 0.3s ease;
}
/* 切换按钮 + 悬浮提示 */
.globe-wrap {
position: relative;
display: inline-flex;
flex-direction: column;
align-items: center;
margin-bottom: 0.2rem;
}
/* 地球切换按钮 */
.globe-toggle {
background: none;
border: none;
cursor: pointer;
padding: 0;
display: block;
outline: none;
transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
-webkit-tap-highlight-color: transparent;
}
.globe-toggle:hover {
transform: scale(1.06);
}
.globe-toggle:active {
transform: scale(0.93);
}
.globe-toggle:focus-visible {
outline: 1.5px solid var(--primary);
outline-offset: 6px;
border-radius: 50%;
}
/* 悬停提示(绝对定位,不占文档流空间)*/
.globe-hint {
position: absolute;
bottom: calc(100% + 12px);
left: 50%;
transform: translateX(-50%) translateY(4px);
display: flex;
flex-direction: column;
align-items: center;
gap: 3px;
opacity: 0;
transition: opacity 0.35s ease, transform 0.35s ease;
pointer-events: none;
white-space: nowrap;
/* 卡片 */
/* -webkit-backdrop-filter: blur(8px);
backdrop-filter: blur(8px);
border: 1px solid var(--line);
padding: 6px 10px;
border-radius: 10px; */
}
/* 桌面端:鼠标悬停显示 */
@media (hover: hover) {
.globe-wrap:hover .globe-hint {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
}
/* 触屏/桌面端通用:JS 手动触发 */
.globe-hint.touch-show {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
.globe-hint-time {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
font-size: 0.78rem;
letter-spacing: 0.10em;
color: var(--text);
transition: color 0.6s ease;
}
.globe-hint-action {
font-size: 0.68rem;
letter-spacing: 0.06em;
color: var(--text-light);
transition: color 0.6s ease;
}
/* 轨道系统旋转由 JS 驱动(SVG 属性动画)──*/
/* 使用 rotate(angle, 0, 0) SVG 属性而非 CSS transform,
明确以 SVG 坐标原点(球心)为旋转轴,无跨浏览器歧义 */
/* 轨道环 */
.g-ring {
fill: none;
stroke: var(--primary);
stroke-width: 0.8;
stroke-dasharray: 2.8 6;
stroke-linecap: round;
opacity: 0.18;
transition: opacity 0.8s ease, stroke 0.8s ease;
}
html.dark .g-ring {
opacity: 0.22;
}
/*
* 统一可见性逻辑
* 规则:轨道顶部天体 = 升起(明亮),底部天体 = 落下(暗淡)
* 浅色:太阳在顶(升) → 明亮;月亮在底(落) → 暗淡留影
* 深色:月亮在顶(升) → 明亮;太阳在底(落) → 暗淡留影
*/
/* 太阳:浅色=升起明亮,深色=落下暗淡 */
.g-sun-aura {
fill: rgba(245, 158, 11, 0.22);
opacity: 1;
transition: opacity 0.8s ease;
}
html.dark .g-sun-aura {
opacity: 0.08;
}
.g-sun-core {
fill: #f59e0b;
opacity: 1;
transition: fill 0.8s ease, opacity 0.8s ease;
}
html.dark .g-sun-core {
fill: #92400e;
opacity: 0.18;
}
/* 月亮:浅色=落下暗淡留影,深色=升起明亮 */
.g-moon-aura {
fill: rgba(147, 197, 253, 0.18);
opacity: 0.15;
transition: opacity 0.8s ease;
}
html.dark .g-moon-aura {
opacity: 1;
}
.g-moon-face {
fill: #c8d8ee;
opacity: 0.20;
transition: opacity 0.8s ease;
}
html.dark .g-moon-face {
opacity: 1;
}
/* 星点:浅色=极淡,深色=明亮 */
.g-star {
fill: #93c5fd;
opacity: 0.15;
transition: opacity 0.8s ease;
}
html.dark .g-star {
opacity: 0.85;
}
/* 地球笔触*/
.g-globe {
fill: none;
stroke: var(--primary);
stroke-linecap: round;
transition: stroke 0.8s ease;
}
/* 地球外圆 */
.g-globe-main {
stroke-width: 2.0;
}
/* 赤道线 */
.g-equator {
stroke-width: 1.2;
stroke-opacity: 0.40;
}
/* 回归线 */
.g-tropic {
stroke-width: 0.75;
stroke-opacity: 0.28;
fill: none;
}
/* 经线 */
.g-lng {
stroke-width: 1.4;
fill: none;
}
/* 输入框区域 */
form {
width: 100%;
}
.input-group {
position: relative;
display: flex;
align-items: center;
border-bottom: 1px solid var(--line);
margin-bottom: 4.5rem;
padding-bottom: 4px;
transition: border-color 0.4s ease;
}
.input-group:focus-within {
border-color: var(--line-focus);
/* Y轴偏移10px,负扩张半径-8px 抵消四周扩散,使其仅显示在底部 */
box-shadow: 0 10px 15px -8px var(--orbit-glow);
}
.input-wrapper {
flex: 1;
position: relative;
display: flex;
align-items: center;
min-width: 0;
}
/* 状态提示文字 */
.input-hint {
position: absolute;
top: calc(100% + 12px);
left: 0;
font-size: 0.8rem;
color: var(--text-light);
transition: all 0.3s ease;
pointer-events: none;
white-space: nowrap;
display: flex;
align-items: center;
gap: 4px;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
.input-hint.error {
color: var(--error);
}
.input-hint.success {
color: var(--success);
}
.hint-icon {
width: 14px;
height: 14px;
flex-shrink: 0;
}
/* 左侧中转胶囊 */
.transit-capsule {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
width: 0;
opacity: 0;
overflow: hidden;
height: 32px;
background: var(--capsule-bg);
border-radius: 6px;
transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
cursor: help;
color: var(--text-light);
position: relative;
font-size: 13px;
font-weight: 500;
}
.transit-capsule.active {
width: 36px;
opacity: 1;
overflow: visible;
}
.capsule-text {
white-space: nowrap;
display: none;
}
/* 分割线 */
.divider {
width: 2px;
height: 16px;
background-color: var(--line);
border-radius: 1px;
margin: 0;
opacity: 0;
transform: scaleY(0.2);
transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.divider.active {
opacity: 1;
transform: scaleY(1);
margin: 0 14px 0 10px;
}
/* 气泡提示 */
.tooltip {
position: absolute;
bottom: 100%;
left: 50%;
transform: translate(-50%, -8px) scale(0.95);
background: var(--text);
color: var(--bg);
padding: 6px 10px;
border-radius: 6px;
font-size: 12px;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
pointer-events: none;
white-space: nowrap;
opacity: 0;
transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
z-index: 100;
}
/* 左侧胶囊:从左边缘向右展开,小箭头贴左 */
.transit-capsule .tooltip {
left: 0;
transform: translateY(-8px) scale(0.95);
}
.transit-capsule .tooltip::after {
left: 14px;
transform: none;
}
.transit-capsule:hover .tooltip {
opacity: 1;
transform: translateY(-12px) scale(1);
}
/* 右侧复制按钮:从右边缘向左展开,小箭头贴右 */
.copy-btn .tooltip {
left: auto;
right: 0;
transform: translateY(-8px) scale(0.95);
}
.copy-btn .tooltip::after {
left: auto;
right: 10px;
transform: none;
}
.copy-btn:hover .tooltip {
opacity: 1;
transform: translateY(-12px) scale(1);
}
.tooltip::after {
content: '';
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
border: 4px solid transparent;
border-top-color: var(--text);
}
.input-field {
width: 100%;
min-width: 0;
background: transparent;
border: none;
outline: none;
padding: 4px 0;
font-size: 1.15rem;
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
transition: font-size 0.3s ease, color 0.15s ease;
}
.input-field::placeholder {
color: var(--text-light);
font-size: 1.1rem;
opacity: 0.6;
font-family: inherit;
}
/* 右侧复制按钮 */
.copy-btn {
width: 0;
opacity: 0;
overflow: hidden;
height: 32px;
background: transparent;
border: none;
color: var(--text-light);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
position: relative;
}
.copy-btn.active {
width: 32px;
opacity: 1;
margin-left: 8px;
overflow: visible;
}
.copy-btn:hover {
color: var(--text);
}
/* 主按钮 */
.submit-btn {
background: var(--primary);
color: var(--bg);
border: none;
padding: 14px 50px;
border-radius: 50px;
font-size: 0.95rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease, background 0.8s ease, color 0.6s ease;
opacity: 1;
pointer-events: none;
display: inline-flex;
align-items: center;
gap: 10px;
}
/* 禁用态:背景透明度单独控制,保持实色背景 */
html:not(.dark) .submit-btn:not(.ready) {
background: rgb(224, 224, 224);
color: var(--primary-disabled);
}
html.dark .submit-btn:not(.ready) {
background: rgb(35, 35, 35);
color: var(--primary-disabled);
}
.submit-btn.ready {
opacity: 1;
pointer-events: auto;
}
.submit-btn.ready:hover {
transform: translateY(-1px);
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--primary-disabled);
transition: background 0.3s;
}
.dot-checking {
background: var(--warn);
animation: pulse 1.5s infinite ease-in-out;
}
.dot-ok {
background: var(--success);
}
@keyframes pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.4;
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
footer {
padding: 30px 20px;
font-size: 0.75rem;
color: var(--text-light);
text-align: center;
position: relative;
z-index: 1;
transition: color 0.6s ease;
}
footer a {
color: var(--text);
text-decoration: none;
border-bottom: 1px dotted var(--text-light);
transition: opacity 0.2s, color 0.6s ease;
}
footer a:hover {
opacity: 0.7;
}
.disclaimer {
margin-top: 8px;
opacity: 0.7;
}
/* 大屏*/
@media (min-width: 1024px) {
.main-container {
max-width: 800px;
}
h1 {
font-size: 2.8rem;
}
.tagline {
font-size: 1.15rem;
}
.input-field {
font-size: 1.25rem;
}
}
/* 手机端*/
@media (max-width: 480px) {
h1 {
font-size: 2rem;
}
.tagline {
font-size: 0.95rem;
margin-bottom: 3rem;
}
.input-field {
font-size: 1rem;
}
.input-hint{
top: calc(100% + 13px);
}
.transit-capsule.active {
width: 36px;
}
.capsule-text {
display: none;
}
.divider.active {
margin: 0 10px 0 8px;
}
.submit-btn {
padding: 14px 46px;
justify-content: center;
}
.tooltip {
display: none;
}
}
@media (max-height: 700px) {
.main-container {
padding: 80px 24px 80px !important;
}
}
</style>
</head>
<body>
<!-- 星空画布(深色模式专用)-->
<canvas id="starField"></canvas>
<div class="main-container">