forked from hassanmsthf11/unlimited-claude-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html-old
More file actions
800 lines (741 loc) · 42.2 KB
/
Copy pathindex.html-old
File metadata and controls
800 lines (741 loc) · 42.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>G4F · Multi‑Provider AI Chat</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet">
<style>
/* ----- (same Claude‑inspired CSS as in your example, condensed for brevity) ----- */
:root {
--bg-0: #0a0a0a;
--bg-1: #111111;
--bg-2: #181818;
--bg-3: #202020;
--bg-4: #2a2a2a;
--border: rgba(255,255,255,0.07);
--border-hi: rgba(255,255,255,0.13);
--accent: #ff6b35;
--accent-glow: rgba(255,107,53,0.18);
--accent-hi: #ff7d4d;
--text-1: #f0f0f0;
--text-2: #909090;
--text-3: #505050;
--green: #34d399;
--red: #f87171;
--blue: #60a5fa;
--font: 'DM Sans', -apple-system, sans-serif;
--mono: 'JetBrains Mono', 'Fira Code', monospace;
--r: 10px;
--r-sm: 6px;
--r-lg: 16px;
--ease: all 0.18s cubic-bezier(0.4,0,0.2,1);
}
* { margin:0; padding:0; box-sizing:border-box; }
html,body { font-family:var(--font); background:var(--bg-0); color:var(--text-1); height:100vh; overflow:hidden; font-size:15px; -webkit-font-smoothing:antialiased; }
::-webkit-scrollbar { width:4px; height:4px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:var(--bg-4); border-radius:2px; }
.app { display:flex; height:100vh; }
/* Sidebar (same) */
.sidebar { width:256px; flex-shrink:0; background:var(--bg-1); border-right:1px solid var(--border); display:flex; flex-direction:column; }
.sb-head { padding:18px 14px 14px; border-bottom:1px solid var(--border); }
.logo { display:flex; align-items:center; gap:9px; font-size:16.5px; font-weight:600; letter-spacing:-0.3px; margin-bottom:14px; }
.logo-mark { width:26px; height:26px; background:var(--accent); border-radius:7px; display:flex; align-items:center; justify-content:center; box-shadow:0 0 14px var(--accent-glow); }
.new-btn { display:flex; align-items:center; gap:7px; width:100%; background:var(--bg-3); border:1px solid var(--border); color:var(--text-1); font-size:13px; font-weight:500; padding:8px 11px; border-radius:var(--r-sm); cursor:pointer; transition:var(--ease); }
.new-btn:hover { background:var(--bg-4); border-color:var(--border-hi); }
.sb-nav { padding:8px 6px; border-bottom:1px solid var(--border); }
.nav-item { display:flex; align-items:center; gap:9px; padding:7px 8px; border-radius:var(--r-sm); color:var(--text-2); font-size:13px; cursor:pointer; transition:var(--ease); }
.nav-item:hover { color:var(--text-1); background:var(--bg-3); }
.sb-body { flex:1; overflow-y:auto; padding:10px 6px; }
.sec-label { font-size:10px; color:var(--text-3); font-weight:700; text-transform:uppercase; letter-spacing:0.1em; padding:0 8px; margin-bottom:6px; }
.recent-item { padding:6px 8px; border-radius:var(--r-sm); color:var(--text-2); font-size:12.5px; cursor:pointer; transition:var(--ease); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.recent-item:hover { color:var(--text-1); background:var(--bg-3); }
.recent-item.active { color:var(--text-1); background:var(--bg-3); }
.empty-hint { padding:8px; color:var(--text-3); font-size:12px; font-style:italic; }
.sb-foot { padding:10px 6px; border-top:1px solid var(--border); }
.user-row { display:flex; align-items:center; gap:9px; padding:7px 8px; border-radius:var(--r-sm); cursor:pointer; transition:var(--ease); }
.user-row:hover { background:var(--bg-3); }
.user-av { width:28px; height:28px; background:var(--accent); border-radius:7px; display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:700; color:white; box-shadow:0 0 10px var(--accent-glow); }
.user-name { font-size:13px; font-weight:500; }
.user-sub { font-size:11px; color:var(--text-3); }
/* Main */
.main { flex:1; display:flex; flex-direction:column; overflow:hidden; background:var(--bg-0); }
/* Welcome screen */
.welcome { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; padding:40px 24px; animation:fadeUp 0.35s ease both; }
@keyframes fadeUp { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:translateY(0); } }
.w-greeting { font-size:28px; font-weight:300; letter-spacing:-0.5px; margin-bottom:28px; display:flex; align-items:center; gap:11px; color:var(--text-1); }
.input-wrap { width:100%; max-width:600px; position:relative; margin-bottom:12px; }
.chat-input { width:100%; padding:13px 50px 13px 15px; background:var(--bg-2); border:1px solid var(--border); border-radius:var(--r); color:var(--text-1); font-size:14.5px; font-family:var(--font); outline:none; resize:none; min-height:50px; max-height:160px; line-height:1.55; transition:border-color 0.2s, box-shadow 0.2s; }
.chat-input:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-glow); }
.chat-input::placeholder { color:var(--text-3); }
.input-btns { position:absolute; right:7px; bottom:7px; display:flex; align-items:center; gap:4px; }
.send-btn { width:32px; height:32px; background:var(--accent); border:none; border-radius:var(--r-sm); color:white; cursor:pointer; display:flex; align-items:center; justify-content:center; transition:var(--ease); }
.send-btn:hover:not(:disabled) { background:var(--accent-hi); box-shadow:0 0 14px var(--accent-glow); transform:scale(1.06); }
.send-btn:disabled { background:var(--bg-4); cursor:not-allowed; }
/* Provider & model bar */
.model-bar { display:flex; align-items:center; gap:8px; margin-bottom:20px; flex-wrap:wrap; justify-content:center; }
.provider-pill, .model-pill { display:inline-flex; align-items:center; gap:6px; background:var(--bg-2); border:1px solid var(--border); border-radius:100px; padding:5px 10px; color:var(--text-2); font-size:12px; font-family:var(--mono); cursor:pointer; transition:var(--ease); white-space:nowrap; }
.provider-pill:hover, .model-pill:hover { background:var(--bg-3); border-color:var(--border-hi); color:var(--text-1); }
.m-dot { width:6px; height:6px; border-radius:50%; background:var(--green); box-shadow:0 0 5px var(--green); flex-shrink:0; transition:var(--ease); }
.m-dot.spinning { background:var(--text-3); box-shadow:none; animation:pulse 1s ease infinite; }
.m-dot.err { background:var(--red); box-shadow:0 0 5px var(--red); }
@keyframes pulse { 0%,100% { opacity:0.3; } 50% { opacity:1; } }
.dropdown-wrap { position:relative; }
.dropdown { position:absolute; bottom:calc(100% + 6px); left:0; background:var(--bg-2); border:1px solid var(--border-hi); border-radius:var(--r); width:300px; max-height:260px; overflow-y:auto; z-index:200; box-shadow:0 8px 32px rgba(0,0,0,0.6); display:none; }
.dropdown.open { display:block; animation:dropIn 0.14s ease both; }
@keyframes dropIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }
.drop-head { padding:9px 12px; border-bottom:1px solid var(--border); font-size:10.5px; color:var(--text-3); font-weight:700; text-transform:uppercase; }
.opt { display:flex; align-items:center; justify-content:space-between; padding:8px 12px; cursor:pointer; transition:var(--ease); border-bottom:1px solid var(--border); }
.opt:last-child { border-bottom:none; }
.opt:hover { background:var(--bg-3); }
.opt.picked { background:rgba(255,107,53,0.07); }
.opt-name { font-size:12.5px; font-family:var(--mono); color:var(--text-1); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:220px; }
.check { color:var(--accent); font-size:13px; }
.auth-chip { display:inline-flex; align-items:center; gap:5px; background:rgba(255,107,53,0.07); border:1px solid rgba(255,107,53,0.2); border-radius:100px; padding:5px 10px; color:var(--accent); font-size:12px; cursor:pointer; transition:var(--ease); }
.auth-chip:hover { background:rgba(255,107,53,0.13); }
.quick-btns { display:flex; gap:8px; flex-wrap:wrap; justify-content:center; max-width:600px; margin-top:12px; }
.quick-btn { display:flex; align-items:center; gap:7px; padding:8px 15px; background:var(--bg-2); border:1px solid var(--border); border-radius:var(--r); color:var(--text-2); font-size:13px; cursor:pointer; transition:var(--ease); }
.quick-btn:hover { background:var(--bg-3); border-color:var(--border-hi); color:var(--text-1); transform:translateY(-1px); }
/* Chat view */
.chat-view { display:none; flex-direction:column; height:100vh; overflow:hidden; }
.chat-view.active { display:flex; }
.chat-thread { flex:1; overflow-y:auto; padding:28px 0 0; scroll-behavior:smooth; }
.thread-inner { max-width:740px; margin:0 auto; padding:0 24px 24px; }
.msg { display:flex; gap:12px; margin-bottom:26px; animation:msgIn 0.22s ease both; }
@keyframes msgIn { from { opacity:0; transform:translateY(7px); } to { opacity:1; transform:translateY(0); } }
.msg.user { flex-direction:row-reverse; }
.msg-av { width:29px; height:29px; border-radius:7px; display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:700; flex-shrink:0; margin-top:1px; }
.msg.user .msg-av { background:var(--accent); color:white; box-shadow:0 0 8px var(--accent-glow); }
.msg.ai .msg-av { background:var(--bg-3); border:1px solid var(--border); color:var(--text-2); }
.msg-body { max-width:calc(100% - 41px); min-width:0; }
.msg.user .msg-body { background:var(--accent); color:white; padding:11px 15px; border-radius:var(--r) 3px var(--r) var(--r); font-size:14.5px; word-wrap:break-word; }
.msg.ai .msg-body { color:var(--text-1); font-size:14.5px; line-height:1.7; }
/* markdown & code (same as original) */
.md p { margin-bottom:11px; }
.md p:last-child { margin-bottom:0; }
.md h1 { font-size:20px; font-weight:600; margin:18px 0 8px; }
.md h2 { font-size:17px; font-weight:600; margin:14px 0 7px; }
.md h3 { font-size:15px; font-weight:600; margin:12px 0 6px; }
.md ul, .md ol { padding-left:22px; margin-bottom:11px; }
.md li { margin-bottom:3px; }
.md strong { font-weight:600; }
.md em { font-style:italic; }
.md del { opacity:0.6; }
.md a { color:var(--accent); text-decoration:underline; }
.md blockquote { border-left:3px solid var(--accent); margin:11px 0; padding:8px 14px; background:var(--bg-2); border-radius:0 var(--r-sm) var(--r-sm) 0; color:var(--text-2); font-style:italic; }
.md code { background:var(--bg-3); color:#f9a875; padding:1px 5px; border-radius:4px; font-family:var(--mono); font-size:13px; }
.md hr { border:none; border-top:1px solid var(--border); margin:16px 0; }
.md table { border-collapse:collapse; width:100%; margin:12px 0; font-size:13.5px; }
.md th, .md td { border:1px solid var(--border); padding:7px 11px; text-align:left; }
.md th { background:var(--bg-3); font-weight:600; }
.code-block { background:var(--bg-1); border:1px solid var(--border); border-radius:var(--r); overflow:hidden; margin:12px 0; }
.cb-head { display:flex; align-items:center; justify-content:space-between; padding:7px 12px; background:var(--bg-2); border-bottom:1px solid var(--border); }
.cb-lang { font-family:var(--mono); font-size:10.5px; color:var(--text-3); text-transform:uppercase; }
.cb-acts { display:flex; gap:5px; }
.cb-btn { display:flex; align-items:center; gap:4px; background:none; border:1px solid var(--border); color:var(--text-3); padding:3px 7px; border-radius:4px; font-size:11px; font-family:var(--font); cursor:pointer; transition:var(--ease); white-space:nowrap; }
.cb-btn:hover { border-color:var(--border-hi); color:var(--text-1); background:var(--bg-3); }
.code-block pre { background:transparent !important; margin:0; padding:14px 16px; }
.code-block code { font-family:var(--mono); font-size:12.5px; }
.typing { display:none; align-items:center; gap:10px; max-width:740px; margin:0 auto; padding:0 24px 16px; }
.typing.on { display:flex; }
.t-av { width:29px; height:29px; border-radius:7px; background:var(--bg-3); border:1px solid var(--border); display:flex; align-items:center; justify-content:center; }
.t-dots { display:flex; gap:4px; }
.t-dot { width:5px; height:5px; background:var(--text-3); border-radius:50%; animation:bounce 1.2s ease infinite; }
.t-dot:nth-child(2) { animation-delay:0.14s; }
.t-dot:nth-child(3) { animation-delay:0.28s; }
@keyframes bounce { 0%,60%,100% { transform:translateY(0); opacity:0.35; } 30% { transform:translateY(-5px); opacity:1; } }
.s-cur { display:inline-block; width:2px; height:1em; background:var(--accent); margin-left:2px; vertical-align:text-bottom; animation:blink 0.65s step-end infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0; } }
.cin-area { padding:10px 24px 18px; background:var(--bg-0); border-top:1px solid var(--border); }
.cin-inner { max-width:740px; margin:0 auto; }
.cin-meta { display:flex; align-items:center; margin-bottom:7px; gap:8px; flex-wrap:wrap; }
.toast { position:fixed; bottom:22px; right:22px; background:var(--bg-4); border:1px solid var(--border-hi); border-radius:var(--r-sm); padding:8px 13px; font-size:12.5px; color:var(--text-1); z-index:9999; opacity:0; transform:translateY(6px); transition:all 0.2s ease; pointer-events:none; }
.toast.show { opacity:1; transform:translateY(0); }
@media (max-width:768px) { .sidebar { width:220px; } }
@media (max-width:520px) { .sidebar { display:none; } }
</style>
</head>
<body>
<div class="app">
<!-- Sidebar -->
<aside class="sidebar">
<div class="sb-head">
<div class="logo">
<div class="logo-mark">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2.5">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
</svg>
</div>
G4F Chat
</div>
<button class="new-btn" id="newChatBtn">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
<line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>
</svg>
New conversation
</button>
</div>
<div class="sb-nav">
<div class="nav-item">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
</svg>
All conversations
</div>
</div>
<div class="sb-body">
<div class="sec-label">Recent</div>
<div id="recentList"><div class="empty-hint">No conversations yet</div></div>
</div>
<div class="sb-foot">
<div class="user-row">
<div class="user-av">👤</div>
<div>
<div class="user-name">Guest</div>
<div class="user-sub">Free · G4F</div>
</div>
</div>
</div>
</aside>
<!-- Main -->
<main class="main">
<!-- Welcome screen -->
<div class="welcome" id="welcomeScreen">
<div class="w-greeting">
<svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z"/>
</svg>
<span id="greetingText">Hello</span>
</div>
<div class="input-wrap">
<textarea class="chat-input" id="welcomeInput" placeholder="What can I help you with?" rows="1"></textarea>
<div class="input-btns">
<button class="send-btn" id="welcomeSendBtn">
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M2 21l21-9L2 3v7l15 2-15 2z"/></svg>
</button>
</div>
</div>
<div class="model-bar">
<!-- Provider dropdown -->
<div class="dropdown-wrap">
<button class="provider-pill" id="providerPill">
<span class="m-dot" id="providerDot"></span>
<span id="providerTxt">pollinations</span>
<svg width="10" height="10" viewBox="0 0 24 24" fill="currentColor"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/></svg>
</button>
<div class="dropdown" id="providerDropdown">
<div class="drop-head">Select provider</div>
<div id="providerList"></div>
</div>
</div>
<!-- Model dropdown -->
<div class="dropdown-wrap">
<button class="model-pill" id="modelPill">
<span class="m-dot" id="modelDot"></span>
<span id="modelTxt">gpt-4o</span>
<svg width="10" height="10" viewBox="0 0 24 24" fill="currentColor"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/></svg>
</button>
<div class="dropdown" id="modelDropdown">
<div class="drop-head">Select model</div>
<div id="modelList"></div>
</div>
</div>
<!-- Optional API key note -->
<div class="auth-chip" id="authNote">🔑 API key? Use custom URL</div>
</div>
<div class="quick-btns">
<button class="quick-btn" data-prompt="Help me write ">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/>
</svg>
Write
</button>
<button class="quick-btn" data-prompt="Help me code ">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>
</svg>
Code
</button>
<button class="quick-btn" data-prompt="Analyze and explain ">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="20" x2="18" y2="10"/>
<line x1="12" y1="20" x2="12" y2="4"/>
<line x1="6" y1="20" x2="6" y2="14"/>
</svg>
Analyze
</button>
<button class="quick-btn" data-prompt="Explain ">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="16" x2="12" y2="12"/>
<line x1="12" y1="8" x2="12.01" y2="8"/>
</svg>
Explain
</button>
</div>
</div>
<!-- Chat view -->
<div class="chat-view" id="chatView">
<div class="chat-thread" id="chatThread">
<div class="thread-inner" id="threadInner"></div>
</div>
<div class="typing" id="typingBubble">
<div class="t-av">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#666" stroke-width="2">
<circle cx="12" cy="12" r="5"/>
<path d="M12 1v4M12 19v4M4.22 4.22l2.83 2.83M16.95 16.95l2.83 2.83M1 12h4M19 12h4M4.22 19.78l2.83-2.83M16.95 7.05l2.83-2.83"/>
</svg>
</div>
<div class="t-dots">
<div class="t-dot"></div>
<div class="t-dot"></div>
<div class="t-dot"></div>
</div>
</div>
<div class="cin-area">
<div class="cin-inner">
<div class="cin-meta">
<span style="color:var(--text-3); font-size:12px;">Using <span id="cinProviderLabel">pollinations</span> · <span id="cinModelLabel">gpt-4o</span></span>
</div>
<div class="cin-bar">
<textarea class="chat-input" id="chatInput" placeholder="Message…" rows="1"></textarea>
<div class="input-btns">
<button class="send-btn" id="chatSendBtn">
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M2 21l21-9L2 3v7l15 2-15 2z"/></svg>
</button>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
<div class="toast" id="toast"></div>
<!-- Prism for syntax highlighting -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-markup.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-bash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js"></script>
<script>
(function() {
// ----- Configuration -----
const PROVIDERS = [
{ name: 'Groq', base: 'https://g4f.space/api/groq' },
{ name: 'Ollama', base: 'https://g4f.space/api/ollama' },
{ name: 'Pollinations', base: 'https://g4f.space/api/pollinations' },
{ name: 'Nvidia', base: 'https://g4f.space/api/nvidia' },
{ name: 'Gemini', base: 'https://g4f.space/api/gemini' },
{ name: 'Auto', base: 'https://g4f.space/api/auto' },
{ name: 'Custom…', base: 'custom' }
];
// Static model list (fallback if /models fails)
const FALLBACK_MODELS = [
'gpt-4o', 'gpt-4', 'gpt-3.5-turbo', 'claude-3-opus', 'claude-3-sonnet',
'llama-3-70b', 'gemini-pro', 'deepseek-v3', 'mistral-large'
];
// State
let currentProvider = PROVIDERS[2]; // Pollinations
let currentModel = 'gpt-4o';
let models = [...FALLBACK_MODELS];
let messages = []; // current conversation
let conversations = []; // list of { id, title, messages }
let activeConvId = null;
let streaming = false;
// DOM elements
const providerPill = document.getElementById('providerPill');
const providerTxt = document.getElementById('providerTxt');
const providerDropdown = document.getElementById('providerDropdown');
const providerList = document.getElementById('providerList');
const modelPill = document.getElementById('modelPill');
const modelTxt = document.getElementById('modelTxt');
const modelDropdown = document.getElementById('modelDropdown');
const modelList = document.getElementById('modelList');
const providerDot = document.getElementById('providerDot');
const modelDot = document.getElementById('modelDot');
const welcomeScreen = document.getElementById('welcomeScreen');
const chatView = document.getElementById('chatView');
const threadInner = document.getElementById('threadInner');
const welcomeInput = document.getElementById('welcomeInput');
const chatInput = document.getElementById('chatInput');
const welcomeSendBtn = document.getElementById('welcomeSendBtn');
const chatSendBtn = document.getElementById('chatSendBtn');
const typingBubble = document.getElementById('typingBubble');
const recentList = document.getElementById('recentList');
const greetingText = document.getElementById('greetingText');
const cinProviderLabel = document.getElementById('cinProviderLabel');
const cinModelLabel = document.getElementById('cinModelLabel');
const authNote = document.getElementById('authNote');
const newChatBtn = document.getElementById('newChatBtn');
const toast = document.getElementById('toast');
// Helper: show toast
function showToast(msg) {
toast.textContent = msg;
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 2200);
}
// Helper: set dot state
function setDot(dotEl, state) {
dotEl.className = 'm-dot';
if (state === 'loading') dotEl.classList.add('spinning');
else if (state === 'error') dotEl.style.cssText = 'background:var(--red);box-shadow:0 0 5px var(--red)';
else dotEl.style.cssText = '';
}
// Populate provider dropdown
function renderProviders() {
providerList.innerHTML = '';
PROVIDERS.forEach(p => {
const opt = document.createElement('div');
opt.className = 'opt' + (p.base === currentProvider.base ? ' picked' : '');
opt.innerHTML = `<span class="opt-name">${p.name}</span><span class="check" style="${p.base !== currentProvider.base ? 'display:none' : ''}">✓</span>`;
opt.addEventListener('click', (e) => {
e.stopPropagation();
if (p.base === 'custom') {
const customUrl = prompt('Enter custom base URL (e.g., https://g4f.space/v1):', 'https://g4f.space/v1');
if (customUrl) {
currentProvider = { name: 'Custom', base: customUrl };
providerTxt.textContent = 'custom';
fetchModelsForProvider(currentProvider.base);
}
} else {
currentProvider = p;
providerTxt.textContent = p.name.toLowerCase();
fetchModelsForProvider(p.base);
}
providerDropdown.classList.remove('open');
renderProviders(); // update checkmark
updateProviderLabel();
});
providerList.appendChild(opt);
});
}
// Fetch models from provider's /models endpoint
async function fetchModelsForProvider(baseUrl) {
setDot(providerDot, 'loading');
setDot(modelDot, 'loading');
modelTxt.textContent = 'Loading…';
try {
const url = baseUrl.replace(/\/$/, '') + '/models';
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
// Extract model list: handle common response shapes
let list = data.data || data.models || data;
if (!Array.isArray(list)) list = FALLBACK_MODELS;
models = list.map(m => (typeof m === 'string' ? m : m.id)).filter(Boolean);
if (models.length === 0) models = FALLBACK_MODELS;
currentModel = models[0];
setDot(providerDot, 'ok');
setDot(modelDot, 'ok');
renderModels();
showToast(`Loaded ${models.length} models`);
} catch (err) {
console.warn('Model fetch failed, using fallback', err);
models = FALLBACK_MODELS;
currentModel = models[0];
setDot(providerDot, 'error');
setDot(modelDot, 'error');
renderModels();
}
modelTxt.textContent = currentModel;
}
// Populate model dropdown
function renderModels() {
modelList.innerHTML = '';
models.forEach(m => {
const opt = document.createElement('div');
opt.className = 'opt' + (m === currentModel ? ' picked' : '');
opt.innerHTML = `<span class="opt-name">${m}</span><span class="check" style="${m !== currentModel ? 'display:none' : ''}">✓</span>`;
opt.addEventListener('click', (e) => {
e.stopPropagation();
currentModel = m;
modelTxt.textContent = m;
modelDropdown.classList.remove('open');
renderModels();
updateProviderLabel();
});
modelList.appendChild(opt);
});
}
// Update labels in chat bar
function updateProviderLabel() {
cinProviderLabel.textContent = currentProvider.name === 'Custom' ? 'custom' : currentProvider.name.toLowerCase();
cinModelLabel.textContent = currentModel;
}
// Toggle dropdowns
function closeAllDropdowns() {
providerDropdown.classList.remove('open');
modelDropdown.classList.remove('open');
}
providerPill.addEventListener('click', (e) => {
e.stopPropagation();
const wasOpen = providerDropdown.classList.contains('open');
closeAllDropdowns();
if (!wasOpen) providerDropdown.classList.add('open');
});
modelPill.addEventListener('click', (e) => {
e.stopPropagation();
const wasOpen = modelDropdown.classList.contains('open');
closeAllDropdowns();
if (!wasOpen) modelDropdown.classList.add('open');
});
document.addEventListener('click', closeAllDropdowns);
[providerDropdown, modelDropdown].forEach(d => d.addEventListener('click', e => e.stopPropagation()));
// ----- Messaging -----
async function sendMessage(text) {
if (streaming) return;
streaming = true;
// Append user message
appendUserMessage(text);
messages.push({ role: 'user', content: text });
// Show typing indicator
typingBubble.classList.add('on');
setInputsEnabled(false);
try {
const { bodyEl, cursor } = appendAIMessage();
let fullText = '';
const response = await fetch(currentProvider.base + '/chat/completions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: currentModel,
messages: messages,
stream: true
})
});
if (!response.ok) {
const errText = await response.text();
throw new Error(`HTTP ${response.status}: ${errText}`);
}
const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop() || '';
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6);
if (data === '[DONE]') continue;
try {
const parsed = JSON.parse(data);
const content = parsed.choices?.[0]?.delta?.content || '';
if (content) {
fullText += content;
renderMarkdown(fullText, bodyEl, cursor);
scrollThread();
}
} catch (e) {
// ignore parse errors
}
}
}
}
// Final render
cursor.remove();
renderMarkdown(fullText, bodyEl, null);
if (window.Prism) Prism.highlightAll();
scrollThread();
messages.push({ role: 'assistant', content: fullText });
saveConversation();
} catch (err) {
console.error(err);
typingBubble.classList.remove('on');
const errMsg = err.message.includes('Failed to fetch')
? 'Network error – possibly blocked or CORS issue.'
: `Error: ${err.message}`;
appendErrorMessage(errMsg);
if (messages[messages.length-1]?.role === 'user') messages.pop();
} finally {
streaming = false;
typingBubble.classList.remove('on');
setInputsEnabled(true);
chatInput?.focus();
}
}
// UI message helpers
function appendUserMessage(text) {
const div = document.createElement('div');
div.className = 'msg user';
div.innerHTML = `<div class="msg-av">👤</div><div class="msg-body">${escapeHtml(text)}</div>`;
threadInner.appendChild(div);
scrollThread();
}
function appendAIMessage() {
const msg = document.createElement('div');
msg.className = 'msg ai';
msg.innerHTML = `<div class="msg-av">🤖</div><div class="msg-body md"></div>`;
threadInner.appendChild(msg);
const bodyEl = msg.querySelector('.msg-body');
const cursor = document.createElement('span');
cursor.className = 's-cur';
bodyEl.appendChild(cursor);
scrollThread();
return { bodyEl, cursor };
}
function appendErrorMessage(text) {
const div = document.createElement('div');
div.className = 'msg ai';
div.innerHTML = `<div class="msg-av">⚠️</div><div class="msg-body md msg-err">${escapeHtml(text)}</div>`;
threadInner.appendChild(div);
scrollThread();
}
// Markdown rendering (simplified, using same functions from original)
function renderMarkdown(src, container, cursor) {
container.innerHTML = '';
parseMarkdown(src).forEach(node => container.appendChild(node));
if (cursor) container.appendChild(cursor);
}
// Very basic markdown parser (inline only; for full version, consider using marked)
function parseMarkdown(src) {
const nodes = [];
const paragraphs = src.split('\n\n');
for (let p of paragraphs) {
if (!p.trim()) continue;
const el = document.createElement('p');
el.innerHTML = inlineMarkdown(p);
nodes.push(el);
}
return nodes;
}
function inlineMarkdown(s) {
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.+?)\*/g, '<em>$1</em>')
.replace(/`(.+?)`/g, '<code>$1</code>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank">$1</a>');
}
function escapeHtml(s) {
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
function scrollThread() {
const t = document.getElementById('chatThread');
if (t) t.scrollTop = t.scrollHeight;
}
function setInputsEnabled(en) {
[welcomeInput, chatInput, welcomeSendBtn, chatSendBtn].forEach(el => {
if (el) el.disabled = !en;
});
}
// Conversation management
function startNewConversation(firstMsg) {
activeConvId = 'c' + Date.now();
const title = firstMsg.length > 40 ? firstMsg.slice(0,40)+'…' : firstMsg;
conversations.unshift({ id: activeConvId, title, messages: [] });
if (conversations.length > 10) conversations.pop();
renderRecent();
}
function saveConversation() {
const conv = conversations.find(c => c.id === activeConvId);
if (conv) {
conv.messages = [...messages];
conv.title = messages.find(m => m.role === 'user')?.content.slice(0,40) + '…' || 'Conversation';
}
renderRecent();
}
function loadConversation(id) {
const conv = conversations.find(c => c.id === id);
if (!conv) return;
activeConvId = id;
messages = [...conv.messages];
threadInner.innerHTML = '';
messages.forEach(m => {
if (m.role === 'user') appendUserMessage(m.content);
else {
const { bodyEl, cursor } = appendAIMessage();
cursor.remove();
renderMarkdown(m.content, bodyEl, null);
}
});
if (window.Prism) Prism.highlightAll();
showChatView();
}
function renderRecent() {
recentList.innerHTML = '';
if (conversations.length === 0) {
recentList.innerHTML = '<div class="empty-hint">No conversations yet</div>';
return;
}
conversations.forEach(c => {
const div = document.createElement('div');
div.className = 'recent-item' + (c.id === activeConvId ? ' active' : '');
div.textContent = c.title;
div.onclick = () => loadConversation(c.id);
recentList.appendChild(div);
});
}
function showChatView() {
welcomeScreen.style.display = 'none';
chatView.classList.add('active');
chatInput.focus();
}
function resetToWelcome() {
messages = [];
activeConvId = null;
threadInner.innerHTML = '';
welcomeScreen.style.display = '';
chatView.classList.remove('active');
welcomeInput.value = '';
welcomeInput.focus();
}
// Event handlers
function handleWelcomeSend() {
const msg = welcomeInput.value.trim();
if (!msg || streaming) return;
welcomeInput.value = '';
startNewConversation(msg);
showChatView();
sendMessage(msg);
}
function handleChatSend() {
const msg = chatInput.value.trim();
if (!msg || streaming) return;
chatInput.value = '';
sendMessage(msg);
}
// Auto-resize textareas
function autoResize(el) {
el.style.height = 'auto';
el.style.height = Math.min(el.scrollHeight, 160) + 'px';
}
[welcomeInput, chatInput].forEach(inp => {
if (!inp) return;
inp.addEventListener('input', () => autoResize(inp));
inp.addEventListener('keydown', e => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
if (inp === welcomeInput) handleWelcomeSend();
else handleChatSend();
}
});
});
welcomeSendBtn.addEventListener('click', handleWelcomeSend);
chatSendBtn.addEventListener('click', handleChatSend);
newChatBtn.addEventListener('click', resetToWelcome);
// Quick prompts
document.querySelectorAll('.quick-btn').forEach(btn => {
btn.addEventListener('click', () => {
welcomeInput.value = btn.dataset.prompt;
autoResize(welcomeInput);
welcomeInput.focus();
});
});
// Greeting
const hour = new Date().getHours();
greetingText.textContent = hour < 12 ? 'Good morning' : hour < 17 ? 'Good afternoon' : 'Good evening';
// Init
renderProviders();
fetchModelsForProvider(currentProvider.base);
updateProviderLabel();
})();
</script>
</body>
</html>