Spaces:
Runtime error

File size: 30,038 Bytes
2570377
 
 
 
 
cc76817
2570377
 
cc76817
2570377
 
cc76817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2570377
 
 
 
 
 
9e217ab
 
 
cc76817
2570377
 
cc76817
2570377
cc76817
3470974
cc76817
3470974
 
 
2570377
 
 
 
9e217ab
 
cc76817
9e217ab
 
cc76817
2570377
 
cc76817
2570377
 
cc76817
 
2570377
 
 
cc76817
2570377
cc76817
 
9e217ab
2570377
 
 
 
cc76817
 
2570377
 
cc76817
 
 
2570377
 
cc76817
 
 
2570377
 
9e217ab
cc76817
 
 
 
 
 
9e217ab
 
cc76817
2570377
 
9e217ab
cc76817
 
9e217ab
 
 
cc76817
9e217ab
cc76817
2570377
 
cc76817
 
2570377
 
 
 
cc76817
 
2570377
 
 
9e217ab
2570377
 
 
 
9e217ab
cc76817
9e217ab
 
 
 
cc76817
 
9e217ab
 
 
cc76817
9e217ab
cc76817
 
9e217ab
cc76817
 
9e217ab
cc76817
9e217ab
 
 
 
 
 
cc76817
 
9e217ab
cc76817
9e217ab
 
2570377
 
 
cc76817
2570377
cc76817
 
 
 
2570377
 
cc76817
2570377
 
9e217ab
cc76817
2570377
 
 
cc76817
 
2570377
 
cc76817
2570377
cc76817
2570377
9e217ab
2570377
 
cc76817
 
2570377
cc76817
2570377
 
 
cc76817
 
2570377
cc76817
2570377
cc76817
2570377
cc76817
 
2570377
 
 
 
 
cc76817
2570377
cc76817
 
9e217ab
 
cc76817
 
 
2570377
 
 
cc76817
 
2570377
9e217ab
2570377
cc76817
9e217ab
2570377
 
 
 
cc76817
9e217ab
2570377
cc76817
2570377
 
9e217ab
 
 
cc76817
 
 
 
2570377
 
 
cc76817
9e217ab
 
cc76817
2570377
 
9e217ab
 
 
2570377
 
 
 
9e217ab
 
cc76817
2570377
 
 
 
cc76817
 
2570377
cc76817
9e217ab
 
 
2570377
 
cc76817
 
2570377
cc76817
2570377
 
 
 
cc76817
2570377
 
 
9e217ab
2570377
 
 
 
 
 
cc76817
2570377
 
9e217ab
cc76817
 
 
 
 
 
2570377
 
9e217ab
2570377
cc76817
2570377
 
9e217ab
 
cc76817
2570377
cc76817
 
9e217ab
 
cc76817
 
7b7f906
cc76817
2570377
 
9e217ab
 
2570377
cc76817
2570377
 
cc76817
7b7f906
 
cc76817
7b7f906
 
 
 
 
cc76817
7b7f906
cc76817
7b7f906
 
 
cc76817
7b7f906
 
 
 
 
cc76817
 
7b7f906
 
cc76817
 
7b7f906
 
 
 
 
 
 
cc76817
9e217ab
2570377
9e217ab
cc76817
 
 
 
 
 
 
 
 
 
9e217ab
2570377
 
cc76817
9e217ab
 
cc76817
9e217ab
cc76817
2570377
 
cc76817
 
2570377
cc76817
2570377
9e217ab
cc76817
2570377
 
9e217ab
2570377
 
cc76817
2570377
cc76817
 
 
 
 
2570377
 
cc76817
1d2a485
cc76817
1d2a485
 
 
cc76817
 
 
1d2a485
 
 
cc76817
 
 
1d2a485
 
 
cc76817
1d2a485
 
cc76817
 
1d2a485
cc76817
 
 
1d2a485
 
 
cc76817
1d2a485
 
cc76817
1d2a485
 
 
 
cc76817
1d2a485
 
 
cc76817
 
1d2a485
cc76817
1d2a485
 
 
cc76817
 
 
1d2a485
 
 
 
 
cc76817
1d2a485
 
 
cc76817
 
1d2a485
 
 
 
cc76817
1d2a485
cc76817
 
1d2a485
 
cc76817
1d2a485
 
cc76817
 
 
 
 
1d2a485
cc76817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d2a485
 
cc76817
 
 
 
 
 
1d2a485
cc76817
 
2570377
 
 
cc76817
2570377
 
 
9e217ab
cc76817
2570377
 
 
9e217ab
cc76817
 
 
 
 
 
 
 
2570377
9e217ab
cc76817
2570377
9e217ab
cc76817
 
9e217ab
 
cc76817
9e217ab
 
 
 
2570377
 
 
9e217ab
 
 
cc76817
9e217ab
2570377
1d2a485
7b7f906
 
 
cc76817
7b7f906
 
cc76817
7b7f906
 
 
1d2a485
cc76817
 
 
 
1d2a485
 
 
 
 
3470974
 
 
 
 
1d2a485
 
 
 
 
 
 
3470974
 
1d2a485
3470974
 
 
 
1d2a485
 
 
2570377
 
9e217ab
cc76817
 
9e217ab
 
2570377
 
 
 
7b7f906
 
 
cc76817
 
 
 
 
 
 
 
 
 
 
 
7b7f906
 
 
 
 
cc76817
 
 
 
 
7b7f906
 
 
cc76817
 
 
 
 
7b7f906
 
 
cc76817
7b7f906
 
 
 
 
 
cc76817
 
 
7b7f906
 
 
 
cc76817
 
7b7f906
cc76817
7b7f906
 
2570377
1d2a485
 
cc76817
1d2a485
cc76817
 
 
1d2a485
 
 
9e217ab
cc76817
 
9e217ab
cc76817
2570377
9e217ab
2570377
9e217ab
ce733c9
2570377
 
9e217ab
cc76817
 
9e217ab
 
cc76817
 
 
2570377
 
cc76817
 
2570377
 
cc76817
7b7f906
2570377
9e217ab
cc76817
 
 
2570377
 
 
cc76817
2570377
 
 
 
cc76817
2570377
 
cc76817
2570377
9e217ab
 
cc76817
9e217ab
 
cc76817
9e217ab
cc76817
 
 
 
9e217ab
 
 
 
cc76817
 
 
2570377
 
 
 
 
 
9e217ab
2570377
 
9e217ab
2570377
cc76817
9e217ab
2570377
6137734
 
 
 
cc76817
9e217ab
 
 
2570377
cc76817
 
2570377
 
cc76817
9e217ab
2570377
cc76817
 
9e217ab
cc76817
2570377
 
cc76817
7b7f906
cc76817
 
2570377
 
 
 
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IP Geo API - IP 地理位置查询</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-primary: #f8fafc;
            --bg-card: #ffffff;
            --bg-code: #1e293b;
            --accent: #0891b2;
            --accent-light: #ecfeff;
            --accent-hover: #0e7490;
            --green: #059669;
            --green-light: #ecfdf5;
            --text-primary: #0f172a;
            --text-secondary: #475569;
            --text-muted: #94a3b8;
            --border: #e2e8f0;
            --border-focus: #0891b2;
            --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
            --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
            --shadow-lg: 0 12px 32px rgba(0,0,0,0.1);
            --radius: 16px;
            --radius-sm: 10px;
        }

        * { margin: 0; padding: 0; box-sizing: border-box; }

        body {
            font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
            background: var(--bg-primary);
            color: var(--text-primary);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            line-height: 1.6;
        }

        .bg-pattern {
            position: fixed;
            inset: 0;
            background-color: #fafaf8;
            background-image:
                linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
                linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
            background-size: 24px 24px;
            z-index: -1;
        }

        .container {
            width: 100%;
            max-width: 800px;
            padding: 24px 20px;
            display: flex;
            flex-direction: column;
            gap: 24px;
        }

        /* Header */
        header {
            text-align: center;
            padding: 40px 0 8px;
            animation: fadeIn 0.6s ease-out;
        }

        h1 {
            font-size: 2rem;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 8px;
            letter-spacing: -0.5px;
        }

        .subtitle {
            color: var(--text-secondary);
            font-size: 1rem;
            font-weight: 400;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-12px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* Search */
        .search-section {
            animation: fadeIn 0.6s ease-out 0.1s backwards;
        }

        .search-box-wrapper {
            background: var(--bg-card);
            padding: 6px;
            border-radius: var(--radius);
            border: 1.5px solid var(--border);
            box-shadow: var(--shadow-md);
            transition: border-color 0.2s, box-shadow 0.2s;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .search-box-wrapper:focus-within {
            border-color: var(--border-focus);
            box-shadow: 0 0 0 3px rgba(8,145,178,0.1), var(--shadow-md);
        }

        .search-icon {
            padding-left: 14px;
            color: var(--text-muted);
            display: flex;
        }

        .search-icon svg { width: 20px; height: 20px; }

        .search-input {
            flex: 1;
            background: transparent;
            border: none;
            padding: 14px 0;
            font-size: 1.05rem;
            color: var(--text-primary);
            font-family: 'JetBrains Mono', monospace;
            outline: none;
            min-width: 0;
        }

        .search-input::placeholder {
            color: var(--text-muted);
            font-family: 'Noto Sans SC', sans-serif;
            font-weight: 400;
        }

        .search-actions {
            display: flex;
            gap: 6px;
            padding-right: 6px;
        }

        .action-btn {
            background: var(--bg-primary);
            border: 1px solid var(--border);
            padding: 10px 14px;
            border-radius: var(--radius-sm);
            color: var(--text-secondary);
            font-size: 0.875rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s;
            white-space: nowrap;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .action-btn svg { width: 16px; height: 16px; }

        .action-btn:hover {
            background: var(--accent-light);
            color: var(--accent);
            border-color: var(--accent);
        }

        .search-btn {
            background: var(--accent);
            border: none;
            padding: 10px 22px;
            border-radius: var(--radius-sm);
            color: white;
            font-size: 0.9rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
            min-width: 76px;
        }

        .search-btn:hover {
            background: var(--accent-hover);
            box-shadow: 0 2px 8px rgba(8,145,178,0.3);
        }

        .search-btn:active { transform: scale(0.97); }

        .search-btn.loading { pointer-events: none; opacity: 0.7; }

        .spinner {
            width: 18px;
            height: 18px;
            border: 2.5px solid rgba(255,255,255,0.3);
            border-top-color: white;
            border-radius: 50%;
            animation: spin 0.7s linear infinite;
            display: none;
        }

        .search-btn.loading .spinner { display: block; }
        .search-btn.loading .btn-text { display: none; }

        @keyframes spin { to { transform: rotate(360deg); } }

        /* Results */
        .result-section {
            min-height: 200px;
            animation: fadeIn 0.4s ease-out;
        }

        .result-card {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow: hidden;
            box-shadow: var(--shadow-lg);
            animation: slideUp 0.4s ease-out;
        }

        @keyframes slideUp {
            from { opacity: 0; transform: translateY(16px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .result-header {
            padding: 28px 32px;
            background: linear-gradient(135deg, var(--accent-light) 0%, #f0fdfa 100%);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
            border-bottom: 1px solid var(--border);
        }

        .result-ip {
            font-family: 'JetBrains Mono', monospace;
            font-size: 2rem;
            font-weight: 700;
            color: var(--accent);
            letter-spacing: 0.5px;
        }

        .result-subnet {
            font-family: 'JetBrains Mono', monospace;
            color: var(--text-muted);
            font-size: 0.85rem;
            background: rgba(8,145,178,0.08);
            padding: 3px 12px;
            border-radius: 20px;
        }

        .result-body {
            padding: 32px;
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 28px;
        }

        .info-group {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .info-item {
            display: flex;
            flex-direction: column;
            gap: 6px;
        }

        .info-label {
            color: var(--text-muted);
            font-size: 0.75rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .info-label svg { width: 14px; height: 14px; color: var(--accent); }

        .info-value {
            font-size: 1.05rem;
            color: var(--text-primary);
            font-weight: 500;
        }

        .info-value.mono { font-family: 'JetBrains Mono', monospace; }

        .info-value.highlight {
            color: var(--accent);
            font-weight: 600;
        }

        .location-path {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 6px;
        }

        .loc-pill {
            background: var(--accent-light);
            color: var(--accent-hover);
            padding: 4px 12px;
            border-radius: 6px;
            font-size: 0.9rem;
            font-weight: 500;
        }

        .loc-sep {
            color: var(--text-muted);
            font-size: 0.75rem;
        }

        .map-btn {
            margin-top: auto;
            background: var(--bg-primary);
            border: 1px dashed var(--border);
            border-radius: var(--radius-sm);
            padding: 10px;
            text-align: center;
            color: var(--text-secondary);
            font-size: 0.875rem;
            font-family: 'JetBrains Mono', monospace;
            cursor: pointer;
            transition: all 0.2s;
        }

        .map-btn:hover {
            border-color: var(--accent);
            color: var(--accent);
            background: var(--accent-light);
        }

        /* Map */
        .map-section {
            display: none;
            animation: slideUp 0.4s ease-out;
        }

        .map-container {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow: hidden;
            box-shadow: var(--shadow-md);
        }

        .map-header {
            padding: 12px 20px;
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--text-secondary);
            font-size: 0.875rem;
            font-weight: 500;
        }

        .map-header svg { width: 16px; height: 16px; color: var(--accent); }

        .map-frame {
            width: 100%;
            height: 400px;
            border: none;
            display: block;
        }

        /* Error */
        .error-state {
            text-align: center;
            padding: 40px;
            background: #fef2f2;
            border: 1px solid #fecaca;
            border-radius: var(--radius);
            color: #dc2626;
        }

        .error-state svg {
            width: 32px;
            height: 32px;
            margin: 0 auto 12px;
            color: #f87171;
        }

        /* Welcome */
        .welcome-state {
            text-align: center;
            padding: 48px 20px;
            color: var(--text-muted);
            font-weight: 400;
        }

        .welcome-state p:first-child { font-size: 1rem; }
        .welcome-state p:last-child { font-size: 0.85rem; margin-top: 8px; opacity: 0.7; }

        /* Footer */
        footer {
            margin-top: auto;
            padding: 32px 20px;
            text-align: center;
            color: var(--text-muted);
            font-size: 0.8rem;
        }

        .credits { margin-top: 6px; }

        .credits a {
            color: var(--accent);
            text-decoration: none;
            font-weight: 500;
            transition: color 0.2s;
        }

        .credits a:hover { color: var(--accent-hover); text-decoration: underline; }

        /* API Docs */
        .api-docs {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 28px;
            box-shadow: var(--shadow-sm);
        }

        .docs-title {
            font-size: 1.05rem;
            font-weight: 600;
            margin-bottom: 16px;
            color: var(--text-primary);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .docs-title svg { width: 18px; height: 18px; color: var(--accent); }

        .code-block {
            background: var(--bg-code);
            border-radius: var(--radius-sm);
            margin-bottom: 12px;
            overflow: hidden;
        }

        .code-block:last-child { margin-bottom: 0; }

        .code-header {
            background: rgba(255,255,255,0.06);
            padding: 8px 16px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid rgba(255,255,255,0.08);
        }

        .code-lang {
            font-size: 0.75rem;
            color: #94a3b8;
            font-weight: 600;
            font-family: 'JetBrains Mono', monospace;
        }

        .copy-btn {
            background: rgba(255,255,255,0.08);
            border: none;
            color: #94a3b8;
            padding: 4px 10px;
            border-radius: 6px;
            font-size: 0.75rem;
            cursor: pointer;
            transition: all 0.2s;
            font-family: 'Noto Sans SC', sans-serif;
        }

        .copy-btn:hover {
            background: rgba(255,255,255,0.15);
            color: white;
        }

        code {
            display: block;
            padding: 14px 16px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.85rem;
            color: #e2e8f0;
            overflow-x: auto;
            white-space: pre;
            line-height: 1.6;
        }

        /* Responsive */
        @media (max-width: 768px) {
            .container { padding: 16px; }
            header { padding: 24px 0 0; }
            h1 { font-size: 1.6rem; }

            .search-box-wrapper {
                flex-direction: column;
                padding: 10px;
                gap: 10px;
            }

            .search-icon { display: none; }

            .search-input {
                padding: 10px;
                text-align: center;
                width: 100%;
            }

            .search-actions {
                width: 100%;
                justify-content: center;
                padding: 0;
            }

            .action-btn, .search-btn {
                flex: 1;
                justify-content: center;
            }

            .result-body {
                grid-template-columns: 1fr;
                padding: 24px;
                gap: 20px;
            }

            .result-ip { font-size: 1.5rem; }
            .map-frame { height: 300px; }
        }

        /* Reduced motion */
        @media (prefers-reduced-motion: reduce) {
            *, *::before, *::after {
                animation-duration: 0.01ms !important;
                transition-duration: 0.01ms !important;
            }
        }

        .hidden { display: none !important; }
    </style>
</head>
<body>
    <div class="bg-pattern"></div>

    <div class="container">
        <header>
            <h1>IP Geo API</h1>
            <p class="subtitle">IP 地理位置与归属地查询</p>
        </header>

        <section class="search-section">
            <div class="search-box-wrapper">
                <span class="search-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
                </span>
                <input
                    type="text"
                    class="search-input"
                    id="ipInput"
                    placeholder="输入 IP 地址..."
                    autocomplete="off"
                    spellcheck="false"
                    aria-label="IP 地址输入"
                >
                <div class="search-actions">
                    <button class="action-btn" onclick="queryMyIP()" title="查询本机IP" aria-label="查询本机IP">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg>
                        <span class="btn-label">我的 IP</span>
                    </button>
                    <button class="search-btn" id="searchBtn" onclick="queryIP()" aria-label="查询">
                        <span class="btn-text">查询</span>
                        <div class="spinner"></div>
                    </button>
                </div>
            </div>
        </section>

        <section class="result-section" id="resultSection">
            <div class="welcome-state">
                <p>输入 IP 地址开始查询</p>
                <p>支持 IPv4 和 IPv6</p>
            </div>
        </section>

        <section class="map-section" id="mapSection">
            <div class="map-container">
                <div class="map-header">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="3 6 9 3 15 6 21 3 21 18 15 21 9 18 3 21"/><line x1="9" x2="9" y1="3" y2="18"/><line x1="15" x2="15" y1="6" y2="21"/></svg>
                    <span>位置标注</span>
                </div>
                <iframe class="map-frame" id="mapFrame" sandbox="allow-scripts allow-same-origin" title="地图"></iframe>
            </div>
        </section>

        <section class="api-docs">
            <h2 class="docs-title">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 18 2 2 4-4"/><path d="M21 12V8.5C21 5.46 18.54 3 15.5 3h-7C5.46 3 3 5.46 3 8.5v7C3 18.54 5.46 21 8.5 21H12"/><path d="M8 8h8"/><path d="M8 12h4"/></svg>
                API 使用说明
            </h2>
            <div class="code-block">
                <div class="code-header">
                    <span class="code-lang">Shell</span>
                    <button class="copy-btn" onclick="copyCode('curl')">复制</button>
                </div>
                <code id="code-curl"># 基础查询
curl https://geo.metaqiu.cn/api/8.8.8.8

# 精确定位(美团数据源)
curl https://geo.metaqiu.cn/api/locate/8.8.8.8</code>
            </div>
            <div class="code-block">
                <div class="code-header">
                    <span class="code-lang">Python</span>
                    <button class="copy-btn" onclick="copyCode('py')">复制</button>
                </div>
                <code id="code-py">import requests

# 基础查询
response = requests.get('https://geo.metaqiu.cn/api/8.8.8.8')
print(response.json())

# 精确定位(美团数据源)
response = requests.get('https://geo.metaqiu.cn/api/locate/8.8.8.8')
print(response.json())</code>
            </div>
        </section>
    </div>

    <footer>
        <p>Powered by MaxMind GeoLite2 &amp; GeoCN</p>
        <p class="credits">Made by <a href="https://metaqiu.cn" target="_blank" rel="noopener">MetaQiu</a></p>
    </footer>

    <script>
        const ipInput = document.getElementById('ipInput');
        const searchBtn = document.getElementById('searchBtn');
        const resultSection = document.getElementById('resultSection');
        const mapSection = document.getElementById('mapSection');
        const mapFrame = document.getElementById('mapFrame');

        // SVG icon helpers
        const icons = {
            globe: '<svg xmlns="http://www.w3.org/2000/svg" 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"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg>',
            building: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="2" width="16" height="20" rx="2" ry="2"/><path d="M9 22v-4h6v4"/><path d="M8 6h.01"/><path d="M16 6h.01"/><path d="M12 6h.01"/><path d="M12 10h.01"/><path d="M12 14h.01"/><path d="M16 10h.01"/><path d="M16 14h.01"/><path d="M8 10h.01"/><path d="M8 14h.01"/></svg>',
            hash: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" x2="20" y1="9" y2="9"/><line x1="4" x2="20" y1="15" y2="15"/><line x1="10" x2="8" y1="3" y2="21"/><line x1="16" x2="14" y1="3" y2="21"/></svg>',
            tag: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2H2v10l9.29 9.29c.94.94 2.48.94 3.42 0l6.58-6.58c.94-.94.94-2.48 0-3.42L12 2Z"/><path d="M7 7h.01"/></svg>',
            clipboard: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="8" height="4" x="8" y="2" rx="1" ry="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/></svg>',
            mapPin: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg>',
            alertTriangle: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>',
        };

        // WGS84 → GCJ02
        function outOfChina(lng, lat) {
            return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271;
        }

        function transformLat(x, y) {
            let r = -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*Math.sqrt(Math.abs(x));
            r += (20.0*Math.sin(6.0*x*Math.PI) + 20.0*Math.sin(2.0*x*Math.PI)) * 2.0/3.0;
            r += (20.0*Math.sin(y*Math.PI) + 40.0*Math.sin(y/3.0*Math.PI)) * 2.0/3.0;
            r += (160.0*Math.sin(y/12.0*Math.PI) + 320*Math.sin(y*Math.PI/30.0)) * 2.0/3.0;
            return r;
        }

        function transformLng(x, y) {
            let r = 300.0 + x + 2.0*y + 0.1*x*x + 0.1*x*y + 0.1*Math.sqrt(Math.abs(x));
            r += (20.0*Math.sin(6.0*x*Math.PI) + 20.0*Math.sin(2.0*x*Math.PI)) * 2.0/3.0;
            r += (20.0*Math.sin(x*Math.PI) + 40.0*Math.sin(x/3.0*Math.PI)) * 2.0/3.0;
            r += (150.0*Math.sin(x/12.0*Math.PI) + 300.0*Math.sin(x/30.0*Math.PI)) * 2.0/3.0;
            return r;
        }

        function wgs84ToGcj02(lng, lat) {
            const a = 6378245.0, ee = 0.00669342162296594323;
            if (outOfChina(lng, lat)) return { lng, lat };
            let dLat = transformLat(lng - 105.0, lat - 35.0);
            let dLng = transformLng(lng - 105.0, lat - 35.0);
            const radLat = lat / 180.0 * Math.PI;
            let magic = Math.sin(radLat);
            magic = 1 - ee * magic * magic;
            const sq = Math.sqrt(magic);
            dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sq) * Math.PI);
            dLng = (dLng * 180.0) / (a / sq * Math.cos(radLat) * Math.PI);
            return { lat: lat + dLat, lng: lng + dLng };
        }

        function updateMap(lat, lng) {
            if (!lat || !lng) { mapSection.style.display = 'none'; return; }
            const c = wgs84ToGcj02(parseFloat(lng), parseFloat(lat));
            const ak = 'nSxiPohfziUaCuONe4ViUP2N';
            mapFrame.src = `https://api.map.baidu.com/marker?location=${c.lat},${c.lng}&title=IP位置&content=IP位置&output=html&coord_type=gcj02&zoom=13&ak=${ak}`;
            mapSection.style.display = 'block';
        }

        function copyCode(type) {
            const el = document.getElementById(`code-${type}`);
            navigator.clipboard.writeText(el.innerText).then(() => {
                const btn = el.parentElement.querySelector('.copy-btn');
                const orig = btn.innerText;
                btn.innerText = '已复制';
                setTimeout(() => btn.innerText = orig, 2000);
            });
        }

        ipInput.focus();
        ipInput.addEventListener('keypress', e => { if (e.key === 'Enter') queryIP(); });
        window.addEventListener('load', () => queryMyIP());

        function queryMyIP() { ipInput.value = ''; queryIP(true); }

        async function queryIP(isMyIP = false) {
            const ip = ipInput.value.trim();
            if (!isMyIP && !ip) return;
            const url = (!ip || isMyIP) ? '/api/' : `/api/${ip}`;
            searchBtn.classList.add('loading');
            try {
                const start = Date.now();
                const res = await fetch(url);
                const data = await res.json();
                const elapsed = Date.now() - start;
                if (elapsed < 300) await new Promise(r => setTimeout(r, 300 - elapsed));
                if (data.error) { showError(data.error); }
                else {
                    if (isMyIP && data.ip) ipInput.value = data.ip;
                    showResult(data);
                }
            } catch { showError('无法连接到服务器,请检查网络'); }
            finally { searchBtn.classList.remove('loading'); }
        }

        function showError(msg) {
            mapSection.style.display = 'none';
            resultSection.innerHTML = `
                <div class="error-state">
                    ${icons.alertTriangle}
                    <div>${msg}</div>
                </div>`;
        }

        function showResult(data) {
            let locationHtml = '<span style="color:var(--text-muted)">未知位置</span>';
            if (data.country || data.regions) {
                const parts = [];
                if (data.country) parts.push(data.country.name);
                if (data.regions) parts.push(...data.regions);
                locationHtml = parts.map(p => `<span class="loc-pill">${p}</span>`).join('<span class="loc-sep">/</span>');
            }

            let ispName = '未知', asn = 'N/A', ispType = '';
            if (data.as) {
                ispName = data.as.info || data.as.name;
                asn = `AS${data.as.number}`;
                if (data.type) ispType = `<span class="result-subnet" style="margin-left:6px">${data.type}</span>`;
            }

            let regHtml = '';
            if (data.registered_country && (!data.country || data.registered_country.code !== data.country.code)) {
                regHtml = `<div class="info-item">
                    <div class="info-label">${icons.clipboard} 注册地</div>
                    <div class="info-value">${data.registered_country.name}</div>
                </div>`;
            }

            let coordsHtml = '';
            if (data.location) {
                coordsHtml = `<div class="map-btn" onclick="updateMap(${data.location.latitude},${data.location.longitude})">
                    ${data.location.latitude}, ${data.location.longitude}
                </div>`;
            }

            resultSection.innerHTML = `
                <div class="result-card">
                    <div class="result-header">
                        <div class="result-ip">${data.ip}</div>
                        <div class="result-subnet">${data.addr || '未知网段'}</div>
                    </div>
                    <div class="result-body">
                        <div class="info-group">
                            <div class="info-item">
                                <div class="info-label">${icons.globe} 地理位置</div>
                                <div class="location-path">${locationHtml}</div>
                            </div>
                            ${data.detail ? `<div class="info-item">
                                <div class="info-label">${icons.mapPin} 详细位置</div>
                                <div class="info-value">${data.detail}</div>
                            </div>` : ''}
                            ${regHtml}
                            ${coordsHtml}
                        </div>
                        <div class="info-group">
                            <div class="info-item">
                                <div class="info-label">${icons.building} 运营商 / ISP</div>
                                <div class="info-value highlight">${ispName}${ispType}</div>
                            </div>
                            <div class="info-item">
                                <div class="info-label">${icons.hash} ASN</div>
                                <div class="info-value mono">${asn}</div>
                            </div>
                            ${data.as && data.as.name !== ispName ? `<div class="info-item">
                                <div class="info-label">${icons.tag} 组织名称</div>
                                <div class="info-value">${data.as.name}</div>
                            </div>` : ''}
                        </div>
                    </div>
                </div>`;

            if (data.location) updateMap(data.location.latitude, data.location.longitude);
            else mapSection.style.display = 'none';
        }
    </script>
</body>
</html>