-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroast_my_code.html
More file actions
1568 lines (1411 loc) · 70.8 KB
/
Copy pathroast_my_code.html
File metadata and controls
1568 lines (1411 loc) · 70.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Roast My Code 🔥</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Syne:wght@700;800&display=swap" rel="stylesheet">
<style>
:root {
--bg: #080810;
--panel: #0e0e1c;
--border: #1e1e35;
--accent: #ff3c5a;
--accent2: #ff8c42;
--green: #00e5a0;
--blue: #4facfe;
--yellow: #ffd166;
--text: #dde1f0;
--dim: #4a4a6a;
--mono: 'JetBrains Mono', monospace;
--display: 'Syne', sans-serif;
--radius: 8px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: var(--bg);
color: var(--text);
font-family: var(--mono);
min-height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ── Fire particles background ── */
#fire-canvas {
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
pointer-events: none;
z-index: 0;
opacity: 0.35;
}
/* ── API bar ── */
#api-bar {
position: relative;
z-index: 10;
padding: 7px 24px;
background: rgba(8,8,16,0.95);
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
gap: 10px;
font-size: 11px;
color: var(--dim);
backdrop-filter: blur(10px);
}
#api-key-input {
flex: 1;
max-width: 340px;
background: rgba(255,255,255,0.04);
border: 1px solid var(--border);
border-radius: 6px;
padding: 5px 12px;
color: var(--text);
font-family: var(--mono);
font-size: 11px;
outline: none;
transition: border-color 0.2s;
}
#api-key-input:focus { border-color: var(--accent); }
.status-pill {
font-size: 10px;
padding: 3px 10px;
border-radius: 20px;
border: 1px solid currentColor;
}
.status-pill.ready { color: var(--green); }
.status-pill.missing { color: var(--accent); }
.warn-note {
margin-left: auto;
font-size: 10px;
color: #333355;
}
/* ── Header ── */
header {
position: relative;
z-index: 10;
padding: 14px 24px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
background: rgba(8,8,16,0.8);
backdrop-filter: blur(10px);
}
.logo {
font-family: var(--display);
font-size: 24px;
font-weight: 800;
background: linear-gradient(90deg, var(--accent), var(--accent2));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
letter-spacing: -0.5px;
}
.header-right {
display: flex;
align-items: center;
gap: 12px;
}
/* ── Intensity slider ── */
.intensity-wrap {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
color: var(--dim);
background: rgba(255,255,255,0.03);
padding: 6px 12px;
border-radius: 20px;
border: 1px solid var(--border);
}
#intensity-slider {
-webkit-appearance: none;
width: 90px;
height: 3px;
border-radius: 2px;
background: linear-gradient(90deg, var(--green), var(--yellow), var(--accent));
outline: none;
cursor: pointer;
}
#intensity-slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 13px; height: 13px;
border-radius: 50%;
background: white;
box-shadow: 0 0 6px rgba(255,60,90,0.6);
cursor: pointer;
}
#intensity-label {
min-width: 70px;
font-size: 10px;
color: var(--text);
text-align: right;
}
/* ── Style selector ── */
#style-select {
background: rgba(255,255,255,0.04);
border: 1px solid var(--border);
border-radius: 6px;
padding: 6px 10px;
color: var(--text);
font-family: var(--mono);
font-size: 11px;
outline: none;
cursor: pointer;
}
/* ── Token counter ── */
#token-display {
font-size: 10px;
color: var(--dim);
padding: 5px 10px;
background: rgba(255,255,255,0.03);
border: 1px solid var(--border);
border-radius: 6px;
}
#token-display span { color: var(--yellow); }
/* ── Main layout ── */
main {
flex: 1;
position: relative;
z-index: 10;
display: flex;
gap: 1px;
background: var(--border);
overflow: hidden;
min-height: 0;
}
.panel {
flex: 1;
background: rgba(14,14,28,0.95);
display: flex;
flex-direction: column;
overflow: hidden;
backdrop-filter: blur(4px);
}
.panel-header {
padding: 9px 16px;
border-bottom: 1px solid var(--border);
font-size: 10px;
color: var(--dim);
text-transform: uppercase;
letter-spacing: 2px;
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.dot { width:7px; height:7px; border-radius:50%; background:var(--accent); flex-shrink:0; }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.blue { background: var(--blue); }
.panel-header-right { margin-left: auto; display: flex; gap: 8px; }
/* ── Editor ── */
.editor-wrapper { flex:1; position:relative; overflow:hidden; }
#highlight-display {
position: absolute; inset: 0;
padding: 18px 18px 18px 60px;
font-family: var(--mono); font-size: 13px; line-height: 1.75;
overflow: auto; white-space: pre; pointer-events: none;
}
#highlight-display pre, #highlight-display code {
background: transparent !important; padding: 0 !important;
font-family: var(--mono) !important; font-size: 13px !important; line-height: 1.75 !important;
}
#code-input {
position: absolute; inset: 0;
padding: 18px 18px 18px 60px;
background: transparent; border: none; outline: none;
color: transparent; caret-color: var(--accent);
font-family: var(--mono); font-size: 13px; line-height: 1.75;
resize: none; z-index: 1; white-space: pre; overflow: auto;
}
.line-numbers {
position: absolute; left:0; top:0; bottom:0; width:46px;
padding: 18px 8px; text-align: right; font-size: 11px; line-height: 1.75;
color: var(--dim); border-right: 1px solid var(--border);
background: rgba(0,0,0,0.3); user-select:none; pointer-events:none; overflow:hidden; z-index:2;
}
/* ── Output panel ── */
#roast-output {
flex: 1; padding: 22px; font-size: 13px; line-height: 1.9;
overflow-y: auto; color: var(--text);
}
.output-placeholder {
display: flex; flex-direction: column; align-items: center;
justify-content: center; height: 100%; gap: 14px; opacity: 0.3;
}
.output-placeholder .big { font-size: 52px; }
.output-placeholder .hint { font-size: 12px; color: var(--dim); }
.roast-text { white-space: pre-wrap; }
.cursor {
display: inline-block; width: 2px; height: 13px;
background: var(--accent); margin-left: 2px;
vertical-align: middle; animation: blink 0.7s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.loading {
display: flex; align-items: center; gap: 12px;
color: var(--dim); padding: 10px 0;
}
.spinner {
width:16px; height:16px;
border: 2px solid var(--border); border-top-color: var(--accent);
border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-msg {
color: var(--accent); padding: 16px;
border: 1px solid rgba(255,60,90,0.2); border-radius: var(--radius);
font-size: 12px; line-height: 1.7;
}
/* ── Score card ── */
.score-card {
margin-top: 20px;
border: 1px solid var(--border);
border-radius: 10px;
overflow: hidden;
}
.score-header {
background: linear-gradient(90deg, rgba(255,60,90,0.15), rgba(255,140,66,0.1));
padding: 12px 18px;
font-family: var(--display);
font-size: 14px;
font-weight: 700;
color: var(--accent);
border-bottom: 1px solid var(--border);
}
.score-body {
padding: 16px 18px;
display: flex;
align-items: center;
gap: 16px;
}
.score-number {
font-family: var(--display);
font-size: 48px;
font-weight: 800;
line-height: 1;
}
.score-bar-wrap {
flex: 1;
}
.score-bar-track {
height: 8px;
background: var(--border);
border-radius: 4px;
overflow: hidden;
}
.score-bar-fill {
height: 100%;
border-radius: 4px;
background: linear-gradient(90deg, var(--accent), var(--accent2));
transition: width 1s cubic-bezier(0.34,1.56,0.64,1);
}
.score-label {
font-size: 12px;
color: var(--dim);
margin-top: 6px;
}
/* ── History panel ── */
#history-panel {
position: fixed;
right: 0; top: 0; bottom: 0;
width: 300px;
background: rgba(8,8,20,0.97);
border-left: 1px solid var(--border);
z-index: 100;
display: flex;
flex-direction: column;
transform: translateX(100%);
transition: transform 0.3s cubic-bezier(0.34,1.2,0.64,1);
backdrop-filter: blur(20px);
}
#history-panel.open { transform: translateX(0); }
.history-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
font-family: var(--display);
font-size: 14px;
font-weight: 700;
color: var(--text);
}
.history-close {
background: none; border: none; color: var(--dim);
cursor: pointer; font-size: 18px; line-height: 1;
padding: 4px;
}
.history-close:hover { color: var(--text); }
#history-list {
flex: 1;
overflow-y: auto;
padding: 12px;
display: flex;
flex-direction: column;
gap: 8px;
}
.history-item {
background: rgba(255,255,255,0.03);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 12px;
cursor: pointer;
transition: border-color 0.2s, background 0.2s;
}
.history-item:hover {
border-color: var(--accent);
background: rgba(255,60,90,0.05);
}
.history-item-lang {
font-size: 10px; color: var(--accent);
text-transform: uppercase; letter-spacing: 1px;
margin-bottom: 4px;
}
.history-item-preview {
font-size: 11px; color: var(--dim);
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
line-height: 1.5;
}
.history-item-time {
font-size: 10px; color: #333355; margin-top: 6px;
}
.history-empty {
text-align: center; color: var(--dim); font-size: 12px;
margin-top: 40px;
}
/* ── Footer ── */
footer {
position: relative; z-index: 10;
padding: 12px 24px;
border-top: 1px solid var(--border);
display: flex;
align-items: center;
gap: 10px;
background: rgba(8,8,16,0.95);
backdrop-filter: blur(10px);
}
#lang-select {
background: rgba(255,255,255,0.04);
border: 1px solid var(--border); border-radius: var(--radius);
padding: 9px 12px; color: var(--text);
font-family: var(--mono); font-size: 12px;
cursor: pointer; outline: none;
}
.icon-btn {
background: rgba(255,255,255,0.04);
border: 1px solid var(--border); border-radius: var(--radius);
padding: 9px 14px; color: var(--dim);
font-family: var(--mono); font-size: 12px;
cursor: pointer; transition: all 0.2s;
white-space: nowrap;
}
.icon-btn:hover { border-color: var(--accent); color: var(--text); }
.icon-btn.active { border-color: var(--green); color: var(--green); }
#roast-btn {
margin-left: auto;
background: linear-gradient(135deg, var(--accent), var(--accent2));
color: white; border: none; border-radius: var(--radius);
padding: 10px 32px; font-family: var(--mono);
font-size: 14px; font-weight: 700;
cursor: pointer; letter-spacing: 0.5px;
transition: transform 0.15s, box-shadow 0.2s;
box-shadow: 0 0 20px rgba(255,60,90,0.25);
}
#roast-btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 6px 28px rgba(255,60,90,0.45);
}
#roast-btn:active:not(:disabled) { transform: translateY(0); }
#roast-btn:disabled { opacity:0.4; cursor:not-allowed; }
#char-count { font-size:10px; color:var(--dim); }
/* ── Copy toast ── */
#toast {
position: fixed;
bottom: 80px; left: 50%;
transform: translateX(-50%) translateY(20px);
background: var(--green); color: #000;
padding: 8px 20px; border-radius: 20px;
font-size: 12px; font-weight: 700;
opacity: 0; transition: all 0.3s;
pointer-events: none; z-index: 999;
}
#toast.show { opacity:1; transform: translateX(-50%) translateY(0); }
/* ── Share image overlay ── */
#share-overlay {
display: none;
position: fixed; inset: 0;
background: rgba(0,0,0,0.85);
z-index: 200;
align-items: center;
justify-content: center;
}
#share-overlay.open { display: flex; }
#share-card {
background: #0e0e1c;
border: 1px solid var(--border);
border-radius: 16px;
padding: 32px;
max-width: 520px;
width: 90%;
position: relative;
}
#share-card-content {
background: linear-gradient(135deg, #0f0f20, #1a0a14);
border: 1px solid rgba(255,60,90,0.2);
border-radius: 12px;
padding: 24px;
margin-bottom: 20px;
}
.share-card-title {
font-family: var(--display);
font-size: 20px;
font-weight: 800;
background: linear-gradient(90deg, var(--accent), var(--accent2));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 12px;
}
#share-roast-text {
font-size: 12px;
line-height: 1.7;
color: var(--dim);
white-space: pre-wrap;
max-height: 200px;
overflow: hidden;
}
.share-footer-text {
font-size: 10px;
color: #333355;
margin-top: 12px;
text-align: right;
}
.share-actions {
display: flex;
gap: 10px;
justify-content: flex-end;
}
.share-close {
position: absolute; top: 16px; right: 16px;
background: none; border: none;
color: var(--dim); cursor: pointer; font-size: 20px;
}
.share-close:hover { color: var(--text); }
</style>
</head>
<body>
<!-- Fire canvas background -->
<canvas id="fire-canvas"></canvas>
<!-- Toast notification -->
<div id="toast">✅ Copied to clipboard!</div>
<!-- Share overlay -->
<div id="share-overlay">
<div id="share-card">
<button class="share-close" id="share-close-btn">×</button>
<div id="share-card-content">
<div class="share-card-title">🔥 Roast My Code</div>
<div id="share-roast-text"></div>
<div class="share-footer-text">roastmycode.dev</div>
</div>
<div class="share-actions">
<button class="icon-btn" id="copy-share-btn">📋 Copy text</button>
<button class="icon-btn" id="download-img-btn">🖼️ Save as image</button>
</div>
</div>
</div>
<!-- History panel -->
<div id="history-panel">
<div class="history-header">
📜 Roast History
<button class="history-close" id="history-close-btn">×</button>
</div>
<div id="history-list">
<div class="history-empty">No roasts yet...</div>
</div>
</div>
<!-- API bar -->
<div id="api-bar">
🔑
<input type="password" id="api-key-input" placeholder="Optional: Add API key for smarter roasts" autocomplete="off"/>
<span class="status-pill ready" id="api-status">● local mode</span>
<span class="warn-note">💡 Works without API key — just paste code and roast!</span>
</div>
<!-- Header -->
<header>
<div class="logo">🔥 Roast My Code</div>
<div class="header-right">
<!-- Token counter -->
<div id="token-display">tokens: <span id="token-count">0</span> (~$<span id="cost-est">0.000</span>)</div>
<!-- Roast style -->
<select id="style-select">
<option value="senior">👨💻 Senior Dev</option>
<option value="gordon">🍳 Gordon Ramsay</option>
<option value="shakespeare">🎭 Shakespearean</option>
<option value="hr">📎 Corporate HR</option>
<option value="friend">🤗 Supportive Friend</option>
</select>
<!-- Intensity -->
<div class="intensity-wrap">
🌡️
<input type="range" id="intensity-slider" min="1" max="5" value="3">
<span id="intensity-label">Balanced</span>
</div>
</div>
</header>
<!-- Main panels -->
<main>
<!-- Left: editor -->
<div class="panel">
<div class="panel-header">
<div class="dot"></div>
your code
<div class="panel-header-right">
<span id="char-count">0 chars</span>
</div>
</div>
<div class="editor-wrapper">
<div id="highlight-display"></div>
<textarea id="code-input" placeholder="// Paste your code here...
// We promise to be... educational."></textarea>
<div class="line-numbers" id="line-numbers">1</div>
</div>
</div>
<!-- Right: roast -->
<div class="panel">
<div class="panel-header">
<div class="dot green" id="output-dot"></div>
the roast
<div class="panel-header-right">
<button class="icon-btn" id="copy-btn" title="Copy roast">📋 Copy</button>
<button class="icon-btn" id="share-btn" title="Share as image">🖼️ Share</button>
<button class="icon-btn" id="fix-btn" title="Fix my code">🛠️ Fix it</button>
</div>
</div>
<div id="roast-output">
<div class="output-placeholder" id="placeholder">
<span class="big">🤖</span>
<span class="hint">Your roast will appear here...</span>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer>
<select id="lang-select">
<option value="auto">🔍 Auto-detect</option>
<option value="python">Python</option>
<option value="javascript">JavaScript</option>
<option value="java">Java</option>
<option value="cpp">C++</option>
<option value="html">HTML/CSS</option>
<option value="typescript">TypeScript</option>
<option value="go">Go</option>
<option value="rust">Rust</option>
</select>
<button class="icon-btn" id="history-btn">📜 History</button>
<span id="char-count-footer" style="font-size:10px;color:var(--dim)"></span>
<button id="roast-btn">🔥 Roast My Code</button>
</footer>
<script>
// ═══════════════════════════════════════════════════════
// FIRE PARTICLE BACKGROUND
// ═══════════════════════════════════════════════════════
const fireCanvas = document.getElementById('fire-canvas')
const fCtx = fireCanvas.getContext('2d')
let fireParticles = []
function resizeFire() {
fireCanvas.width = window.innerWidth
fireCanvas.height = window.innerHeight
}
resizeFire()
window.addEventListener('resize', resizeFire)
function spawnFireParticle() {
fireParticles.push({
x: Math.random() * window.innerWidth,
y: window.innerHeight + 10,
vx: (Math.random() - 0.5) * 0.8,
vy: -(Math.random() * 1.5 + 0.5),
life: 1.0,
size: Math.random() * 3 + 1,
hue: Math.random() * 30 + 5, // orange-red range
})
}
function animateFire() {
fCtx.clearRect(0, 0, fireCanvas.width, fireCanvas.height)
if (Math.random() < 0.4) spawnFireParticle()
fireParticles = fireParticles.filter(p => p.life > 0)
for (const p of fireParticles) {
p.x += p.vx
p.y += p.vy
p.life -= 0.008
p.vx += (Math.random() - 0.5) * 0.1
fCtx.globalAlpha = p.life * 0.6
fCtx.fillStyle = `hsl(${p.hue}, 100%, ${40 + p.life * 40}%)`
fCtx.beginPath()
fCtx.arc(p.x, p.y, p.size * p.life, 0, Math.PI * 2)
fCtx.fill()
}
fCtx.globalAlpha = 1
requestAnimationFrame(animateFire)
}
animateFire()
// ═══════════════════════════════════════════════════════
// ELEMENT REFS
// ═══════════════════════════════════════════════════════
const codeInput = document.getElementById('code-input')
const highlightDisplay = document.getElementById('highlight-display')
const lineNumbers = document.getElementById('line-numbers')
const charCount = document.getElementById('char-count')
const charCountFooter = document.getElementById('char-count-footer')
const langSelect = document.getElementById('lang-select')
const roastBtn = document.getElementById('roast-btn')
const roastOutput = document.getElementById('roast-output')
const apiKeyInput = document.getElementById('api-key-input')
const apiStatus = document.getElementById('api-status')
const outputDot = document.getElementById('output-dot')
const intensitySlider = document.getElementById('intensity-slider')
const intensityLabel = document.getElementById('intensity-label')
const styleSelect = document.getElementById('style-select')
const tokenCount = document.getElementById('token-count')
const costEst = document.getElementById('cost-est')
const copyBtn = document.getElementById('copy-btn')
const shareBtn = document.getElementById('share-btn')
const fixBtn = document.getElementById('fix-btn')
const historyBtn = document.getElementById('history-btn')
const historyPanel = document.getElementById('history-panel')
const historyCloseBtn = document.getElementById('history-close-btn')
const historyList = document.getElementById('history-list')
const toast = document.getElementById('toast')
const shareOverlay = document.getElementById('share-overlay')
const shareCloseBtn = document.getElementById('share-close-btn')
const shareRoastText = document.getElementById('share-roast-text')
const copyShareBtn = document.getElementById('copy-share-btn')
const downloadImgBtn = document.getElementById('download-img-btn')
// ═══════════════════════════════════════════════════════
// STATE
// ═══════════════════════════════════════════════════════
let lastRoastText = ''
let totalTokens = 0
let roastHistory = JSON.parse(localStorage.getItem('roast_history') || '[]')
// ═══════════════════════════════════════════════════════
// API KEY
// ═══════════════════════════════════════════════════════
apiKeyInput.addEventListener('input', () => {
const ok = apiKeyInput.value.trim().startsWith('sk-ant-')
apiStatus.textContent = ok ? '● API ready' : '● local mode'
apiStatus.className = `status-pill ${ok ? 'ready' : 'ready'}`
})
// ═══════════════════════════════════════════════════════
// INTENSITY SLIDER
// ═══════════════════════════════════════════════════════
const INTENSITY_LABELS = ['Be Gentle 🥺','Mild Critique','Balanced 🔥','Pretty Savage','DESTROY ME 💀']
intensitySlider.addEventListener('input', () => {
intensityLabel.textContent = INTENSITY_LABELS[intensitySlider.value - 1]
})
// ═══════════════════════════════════════════════════════
// SYNTAX HIGHLIGHTING
// ═══════════════════════════════════════════════════════
function syncHighlight() {
const code = codeInput.value
const lang = langSelect.value
const len = code.length
charCount.textContent = `${len} chars`
charCountFooter.textContent = `${len} chars`
const lines = code.split('\n').length
lineNumbers.innerHTML = Array.from({ length: lines }, (_, i) => i + 1).join('<br>')
const highlighted = lang === 'auto'
? hljs.highlightAuto(code).value
: hljs.highlight(code, { language: lang }).value
highlightDisplay.innerHTML = `<pre><code>${highlighted}</code></pre>`
highlightDisplay.scrollTop = codeInput.scrollTop
highlightDisplay.scrollLeft = codeInput.scrollLeft
}
codeInput.addEventListener('input', syncHighlight)
langSelect.addEventListener('change', syncHighlight)
codeInput.addEventListener('scroll', () => {
highlightDisplay.scrollTop = codeInput.scrollTop
highlightDisplay.scrollLeft = codeInput.scrollLeft
})
codeInput.addEventListener('keydown', e => {
if (e.key === 'Tab') {
e.preventDefault()
const s = codeInput.selectionStart
codeInput.value = codeInput.value.substring(0, s) + ' ' + codeInput.value.substring(s)
codeInput.selectionStart = codeInput.selectionEnd = s + 2
syncHighlight()
}
})
// ═══════════════════════════════════════════════════════
// PROMPT BUILDER
// ═══════════════════════════════════════════════════════
function buildPrompt(code, lang, style, intensity) {
const langHint = lang === 'auto' ? '' : ` written in ${lang}`
const intensityMap = {
1: 'Be kind and encouraging. Gently point out issues like a patient mentor.',
2: 'Be mildly critical. Point out issues with light humour.',
3: 'Be balanced — funny and savage but always educational.',
4: 'Be pretty savage. Roast hard, but every burn must have a real lesson.',
5: 'MAXIMUM DESTRUCTION. Absolutely obliterate this code. No mercy. Every joke must still be technically accurate.',
}
const stylePersona = {
senior: 'You are a battle-hardened senior developer with 20 years of experience and zero patience for bad code.',
gordon: 'You are Gordon Ramsay, but for code instead of food. Channel his iconic rage and passion.',
shakespeare: 'You are a Shakespearean playwright reviewing code in iambic prose, with dramatic flair and Elizabethan vocabulary.',
hr: 'You are a Corporate HR manager who can only give feedback in passive-aggressive corporate speak and euphemisms.',
friend: 'You are a supportive best friend who is also a great developer — encouraging but honest.',
}
return `${stylePersona[style]}
${intensityMap[intensity]}
Do a code review / roast of the following code${langHint}.
Structure your response EXACTLY like this:
1. 🔥 Opening — one killer opening line about the overall code quality
2. 💀 The Crimes — for each issue found: make a joke, explain WHY it is bad, show a better way
3. 🏆 Saving Grace — one genuine compliment (if nothing is good, compliment their courage)
4. 📊 Verdict — end with a score like "4/10 — Would not merge" on its own line
Keep it punchy. Each crime should be 2-4 sentences. Max 5 crimes total.
Code to review:
\`\`\`
${code}
\`\`\``
}
// ═══════════════════════════════════════════════════════
// TOKEN COUNTER (estimate: ~4 chars per token)
// ═══════════════════════════════════════════════════════
function updateTokens(text) {
const t = Math.round(text.length / 4)
totalTokens += t
tokenCount.textContent = totalTokens
costEst.textContent = (totalTokens * 0.000003).toFixed(4) // ~$3/1M tokens
}
// ═══════════════════════════════════════════════════════
// SCORE CARD PARSER
// ═══════════════════════════════════════════════════════
function extractScore(text) {
const match = text.match(/(\d+)\s*\/\s*10/)
return match ? parseInt(match[1]) : null
}
function renderScoreCard(score, verdict) {
const pct = (score / 10) * 100
const color = score <= 3 ? '#ff3c5a' : score <= 6 ? '#ffd166' : '#00e5a0'
return `
<div class="score-card">
<div class="score-header">📊 Verdict</div>
<div class="score-body">
<div class="score-number" style="color:${color}">${score}</div>
<div class="score-bar-wrap">
<div style="font-size:11px;color:var(--dim);margin-bottom:6px">${verdict}</div>
<div class="score-bar-track">
<div class="score-bar-fill" id="score-fill" style="width:0%;background:linear-gradient(90deg,${color},${color}88)"></div>
</div>
<div class="score-label">${score}/10</div>
</div>
</div>
</div>`
}
// ═══════════════════════════════════════════════════════
// HISTORY
// ═══════════════════════════════════════════════════════
function saveToHistory(code, roast, lang) {
const item = {
id: Date.now(),
lang: lang === 'auto' ? 'auto' : lang,
code: code.substring(0, 200),
roast: roast,
time: new Date().toLocaleTimeString(),
}
roastHistory.unshift(item)
if (roastHistory.length > 5) roastHistory.pop()
localStorage.setItem('roast_history', JSON.stringify(roastHistory))
renderHistory()
}
function renderHistory() {
if (roastHistory.length === 0) {
historyList.innerHTML = '<div class="history-empty">No roasts yet...</div>'
return
}
historyList.innerHTML = roastHistory.map(item => `
<div class="history-item" data-id="${item.id}">
<div class="history-item-lang">${item.lang}</div>
<div class="history-item-preview">${item.roast.substring(0, 120)}...</div>
<div class="history-item-time">🕐 ${item.time}</div>
</div>
`).join('')
historyList.querySelectorAll('.history-item').forEach(el => {
el.addEventListener('click', () => {
const id = parseInt(el.dataset.id)
const item = roastHistory.find(r => r.id === id)
if (!item) return
showRoast(item.roast)
historyPanel.classList.remove('open')
})
})
}
// ═══════════════════════════════════════════════════════
// RENDER ROAST OUTPUT
// ═══════════════════════════════════════════════════════
function showRoast(text) {
const score = extractScore(text)
const verdict = text.match(/\d+\/10\s*[—-]\s*(.+)/)?.[1] || ''
// Split off verdict line to render separately
const mainText = text.replace(/📊.*$/s, '').trim()
let html = `<div class="roast-text">${escapeHtml(mainText)}</div>`
if (score !== null) {
html += renderScoreCard(score, verdict)
}
roastOutput.innerHTML = html
outputDot.className = 'dot green'
// Animate score bar
if (score !== null) {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
const fill = document.getElementById('score-fill')
if (fill) fill.style.width = `${(score/10)*100}%`
})
})
}
}
function escapeHtml(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
}
// ═══════════════════════════════════════════════════════
// LOCAL ROAST GENERATOR (no API key needed)
// ═══════════════════════════════════════════════════════
const ROAST_PATTERNS = [
{ pattern: /var\s+\w+\s*=/gi, roast: "Using `var` in ${year}? Bold choice. Let me guess — you learned JS in 2015.", type: "var" },
{ pattern: /function\s+\w+\s*\(/gi, roast: "Old-school function declaration? Respect for the classics, but arrow functions called — they want to meet their parent.", type: "function" },
{ pattern: /==(?!=)/gi, roast: "Loose equality (`==`)? You're not wrong, you're just... playing Russian roulette with types.", type: "equality" },
{ pattern: /console\.log/gi, roast: "Console.log debugging? We've all been there. But maybe... breakpoints?", type: "console" },
{ pattern: /alert\s*\(/gi, roast: "Using `alert()`? That's not a bug, that's a user experience war crime.", type: "alert" },
{ pattern: /for\s*\(\s*let\s+i=0/gi, roast: "Classic for loop. Nothing wrong — except `forEach` called, it wants to be noticed.", type: "forloop" },
{ pattern: /\.innerHTML\s*=/gi, roast: "innerHTML assignment? XSS says thank you for the invitation to the party.", type: "xss" },
{ pattern: /eval\s*\(/gi, roast: "`eval()`? That's not code execution, that's a security vulnerability with extra steps.", type: "eval" },
{ pattern: /setTimeout\s*\(\s*"/gi, roast: "String in setTimeout? `setInterval` called — it wants to know why its cousin gets all the attention.", type: "settimeout" },
{ pattern: /document\.write/gi, roast: "`document.write()`? That's not a method, it's a fossil. 🦕", type: "write" },
{ pattern: /async\s+function/gi, roast: "Async function! Finally, someone who understands the art of waiting.", type: "async" },
{ pattern: /await\s+/gi, roast: "Using `await` — smooth. Just promise me you won't forget the `try/catch`.", type: "await" },
{ pattern: /try\s*{/gi, roast: "Try block! Smart. The only thing more dangerous than no error handling is thinking you don't need it.", type: "try" },
{ pattern: /catch\s*\(\s*\w+\s*\)/gi, roast: "Empty catch block? That's not error handling — that's error hiding. 👀", type: "catch" },
{ pattern: /class\s+\w+\s*{/gi, roast: "ES6 class! Someone's been drinking the OOP Kool-Aid. No judgment (much).", type: "class" },
{ pattern: /constructor\s*\(/gi, roast: "Constructor? Clean. Just don't forget — with great power comes great responsibility.", type: "constructor" },
{ pattern: /extends\s+\w+/gi, roast: "Inheritance! Bold choice. Composition called — it has some things to discuss with you.", type: "extends" },
{ pattern: /interface\s+\w+/gi, roast: "TypeScript interface! You're living in the future. We mere mortals are impressed.", type: "interface" },