forked from aakash-env/github-receipt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
749 lines (662 loc) · 35 KB
/
Copy pathindex.html
File metadata and controls
749 lines (662 loc) · 35 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub Receipt Generator</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600;700&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3/dist/JsBarcode.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
<style>
/* ===== Reset & Base ===== */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
body{
font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;
min-height:100vh;display:flex;justify-content:center;align-items:flex-start;
padding:40px 20px;background:var(--receipt-ui-bg);color:var(--receipt-fg);
transition:background .3s ease,color .3s ease
}
a{color:var(--receipt-accent)}
/* ===== Theme Tokens (10 themes) ===== */
/* -- Catppuccin Mocha -- */
.theme-catppuccin-mocha{--receipt-bg:#1e1e2e;--receipt-fg:#cdd6f4;--receipt-accent:#89b4fa;--receipt-muted:#a6adc8;--receipt-surface:#313244;--receipt-border:rgba(205,214,244,.15);--receipt-highlight:#cba6f7;--receipt-tear-bg:#181825;--receipt-ui-bg:#11111b;--receipt-subtle:#bac2de}
/* -- Catppuccin Macchiato -- */
.theme-catppuccin-macchiato{--receipt-bg:#24273a;--receipt-fg:#cad3f5;--receipt-accent:#8aadf4;--receipt-muted:#a5adcb;--receipt-surface:#363a4f;--receipt-border:rgba(202,211,245,.15);--receipt-highlight:#c6a0f6;--receipt-tear-bg:#1e2030;--receipt-ui-bg:#181926;--receipt-subtle:#b8c0e0}
/* -- Catppuccin Frappé -- */
.theme-catppuccin-frappe{--receipt-bg:#303446;--receipt-fg:#c6d0f5;--receipt-accent:#8caaee;--receipt-muted:#a5adce;--receipt-surface:#414559;--receipt-border:rgba(198,208,245,.15);--receipt-highlight:#ca9ee6;--receipt-tear-bg:#292c3c;--receipt-ui-bg:#232634;--receipt-subtle:#b5bfe2}
/* -- Catppuccin Latte -- */
.theme-catppuccin-latte{--receipt-bg:#eff1f5;--receipt-fg:#4c4f69;--receipt-accent:#1e66f5;--receipt-muted:#6c6f85;--receipt-surface:#ccd0da;--receipt-border:rgba(76,79,105,.12);--receipt-highlight:#8839ef;--receipt-tear-bg:#dce0e8;--receipt-ui-bg:#e6e9ef;--receipt-subtle:#5c5f77}
/* -- Tokyo Night -- */
.theme-tokyo-night{--receipt-bg:#1a1b26;--receipt-fg:#a9b1d6;--receipt-accent:#7aa2f7;--receipt-muted:#565f89;--receipt-surface:#24283b;--receipt-border:rgba(169,177,214,.15);--receipt-highlight:#bb9af7;--receipt-tear-bg:#16161e;--receipt-ui-bg:#0f0f14;--receipt-subtle:#787c9a}
/* -- Tokyo Night Storm -- */
.theme-tokyo-storm{--receipt-bg:#24283b;--receipt-fg:#a9b1d6;--receipt-accent:#7aa2f7;--receipt-muted:#565f89;--receipt-surface:#2f3348;--receipt-border:rgba(169,177,214,.15);--receipt-highlight:#bb9af7;--receipt-tear-bg:#1e2233;--receipt-ui-bg:#171a24;--receipt-subtle:#787c9a}
/* -- Tokyo Night Moon -- */
.theme-tokyo-moon{--receipt-bg:#222436;--receipt-fg:#c8d3f5;--receipt-accent:#82aaff;--receipt-muted:#7a88cf;--receipt-surface:#2a2c48;--receipt-border:rgba(200,211,245,.15);--receipt-highlight:#fca7ea;--receipt-tear-bg:#1d1e32;--receipt-ui-bg:#181926;--receipt-subtle:#a1ace8}
/* -- Tokyo Night Day -- */
.theme-tokyo-day{--receipt-bg:#e6e7ed;--receipt-fg:#343b58;--receipt-accent:#2959aa;--receipt-muted:#6c6e75;--receipt-surface:#d0d1d9;--receipt-border:rgba(52,59,88,.12);--receipt-highlight:#5a3e8e;--receipt-tear-bg:#d4d5dd;--receipt-ui-bg:#e1e2e7;--receipt-subtle:#565a6e}
/* -- Rosé Pine -- */
.theme-rose-pine{--receipt-bg:#191724;--receipt-fg:#e0def4;--receipt-accent:#c4a7e7;--receipt-muted:#6e6a86;--receipt-surface:#1f1d2e;--receipt-border:rgba(224,222,244,.12);--receipt-highlight:#eb6f92;--receipt-tear-bg:#21202e;--receipt-ui-bg:#13111d;--receipt-subtle:#908caa}
/* -- Rosé Pine Moon -- */
.theme-rose-moon{--receipt-bg:#232136;--receipt-fg:#e0def4;--receipt-accent:#c4a7e7;--receipt-muted:#6e6a86;--receipt-surface:#2a273f;--receipt-border:rgba(224,222,244,.12);--receipt-highlight:#eb6f92;--receipt-tear-bg:#2a283e;--receipt-ui-bg:#1b192b;--receipt-subtle:#908caa}
/* -- Rosé Pine Dawn -- */
.theme-rose-dawn{--receipt-bg:#faf4ed;--receipt-fg:#575279;--receipt-accent:#907aa9;--receipt-muted:#9893a5;--receipt-surface:#fffaf3;--receipt-border:rgba(87,82,121,.12);--receipt-highlight:#b4637a;--receipt-tear-bg:#f4ede8;--receipt-ui-bg:#f2e9e1;--receipt-subtle:#797593}
/* ===== Layout ===== */
.container{max-width:520px;width:100%;}
.header{text-align:center;margin-bottom:24px}
.header h1{font-size:28px;margin-bottom:4px;color:var(--receipt-fg)}
.header p{font-size:14px;color:var(--receipt-muted)}
.controls{display:flex;flex-direction:column;gap:10px;margin-bottom:20px}
.control-row{display:flex;gap:8px}
.control-row .input{flex:1}
.input{padding:10px 14px;border:1px solid var(--receipt-border);border-radius:6px;font-size:14px;outline:none;background:var(--receipt-surface);color:var(--receipt-fg);transition:border-color .2s}
.input:focus{border-color:var(--receipt-accent)}
.input::placeholder{color:var(--receipt-muted);opacity:.6}
.btn{padding:10px 20px;border:none;border-radius:6px;font-size:14px;cursor:pointer;font-weight:600;white-space:nowrap;transition:opacity .2s,transform .1s}
.btn:active{transform:scale(.97)}
.btn-primary{background:var(--receipt-accent);color:var(--receipt-ui-bg)}
.btn-primary:hover{opacity:.9}
.btn-primary:disabled{opacity:.4;cursor:not-allowed}
.btn-outline{background:transparent;color:var(--receipt-fg);border:1px solid var(--receipt-border)}
.btn-outline:hover{background:var(--receipt-surface)}
.btn-download{background:var(--receipt-highlight);color:var(--receipt-ui-bg)}
.btn-download:hover{opacity:.9}
.token-wrap{display:flex;gap:8px;align-items:center}
.token-wrap label{font-size:12px;color:var(--receipt-muted);white-space:nowrap}
.token-wrap input{flex:1;padding:8px 12px;border:1px solid var(--receipt-border);border-radius:6px;font-size:12px;outline:none;background:var(--receipt-surface);color:var(--receipt-fg)}
.token-wrap input:focus{border-color:var(--receipt-accent)}
.token-hint{font-size:11px;color:var(--receipt-muted);margin-bottom:8px}
.token-hint a{color:var(--receipt-accent)}
/* ===== Theme Picker ===== */
.theme-picker{display:flex;gap:6px;overflow-x:auto;padding:4px 0 8px;-webkit-overflow-scrolling:touch;scrollbar-width:thin}
.theme-picker::-webkit-scrollbar{height:3px}
.theme-picker::-webkit-scrollbar-thumb{background:var(--receipt-border);border-radius:2px}
.theme-btn{display:flex;align-items:center;gap:6px;padding:5px 10px;border:1px solid var(--receipt-border);border-radius:6px;background:var(--receipt-surface);color:var(--receipt-fg);cursor:pointer;font-size:11px;white-space:nowrap;transition:all .2s;flex-shrink:0}
.theme-btn:hover{border-color:var(--receipt-accent)}
.theme-btn.active{border-color:var(--receipt-accent);background:rgba(137,180,250,.12)}
.theme-swatch{width:10px;height:10px;border-radius:50%;flex-shrink:0}
.theme-family{font-size:9px;color:var(--receipt-muted);margin-right:2px}
/* ===== Mode Selector ===== */
.mode-selector{display:flex;gap:8px;margin-bottom:16px}
.mode-btn{flex:1;padding:8px;text-align:center;border:1px solid var(--receipt-border);border-radius:6px;background:transparent;color:var(--receipt-muted);cursor:pointer;font-size:13px;font-weight:600;transition:all .2s}
.mode-btn:hover{color:var(--receipt-fg)}
.mode-btn.active{background:var(--receipt-surface);color:var(--receipt-accent);border-color:var(--receipt-accent)}
/* ===== Receipt ===== */
.receipt-wrap{background:var(--receipt-bg);border-radius:8px;box-shadow:0 1px 8px rgba(0,0,0,.2);overflow:hidden;transition:background .3s ease}
.receipt{font-family:'IBM Plex Mono','JetBrains Mono','Fira Code','Courier New',monospace;font-size:13px;line-height:1.7;padding:28px;color:var(--receipt-fg);background:var(--receipt-bg);transition:background .3s ease,color .3s ease}
/* Tear effect */
.tear{height:10px;background:var(--receipt-tear-bg);position:relative;overflow:hidden;transition:background .3s}
.tear::after{content:'';position:absolute;left:0;right:0;top:0;height:100%;background:repeating-linear-gradient(105deg,transparent 0,transparent 6px,var(--receipt-bg) 6px,var(--receipt-bg) 10px);background-size:14px 10px;transition:background .3s}
/* Receipt typography */
.receipt-title{text-align:center;font-size:20px;font-weight:700;letter-spacing:2px;margin-bottom:2px;color:var(--receipt-accent)}
.receipt-sub{text-align:center;font-size:11px;color:var(--receipt-muted);margin-bottom:4px}
.receipt-divider{border:none;height:1px;background:repeating-linear-gradient(to right,var(--receipt-border) 0,var(--receipt-border) 4px,transparent 4px,transparent 8px);margin:10px 0}
.receipt-section-label{font-size:10px;font-weight:700;letter-spacing:1.5px;color:var(--receipt-accent);margin-bottom:4px;text-transform:uppercase}
.receipt-row{display:flex;justify-content:space-between;align-items:baseline;padding:1px 0}
.receipt-row .label{color:var(--receipt-subtle)}
.receipt-row .value{text-align:right}
.receipt-score{font-weight:700;font-size:15px;padding:4px 0}
.receipt-score .value{color:var(--receipt-highlight);font-size:18px}
.receipt-barcode{text-align:center;margin:8px 0 4px}
.receipt-barcode svg{max-width:100%;height:auto}
.receipt-footer{text-align:center;margin-top:8px;font-size:10px;color:var(--receipt-muted);line-height:1.5}
/* ===== Profile Card Mode ===== */
.profile-card .receipt-title{font-size:18px}
.profile-card .receipt-score{text-align:center;display:flex;flex-direction:column;align-items:center;gap:4px}
.profile-card .score-ring{position:relative;width:80px;height:80px;margin:4px auto}
.profile-card .score-ring svg{transform:rotate(-90deg)}
.profile-card .score-ring .bg{fill:none;stroke:var(--receipt-surface);stroke-width:6}
.profile-card .score-ring .fg{fill:none;stroke:var(--receipt-highlight);stroke-width:6;stroke-linecap:round;transition:stroke-dashoffset .8s ease}
.profile-card .score-ring .score-text{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-size:16px;font-weight:700;color:var(--receipt-highlight)}
.profile-card .lang-bar{margin:2px 0;display:flex;align-items:center;gap:8px;font-size:11px}
.profile-card .lang-bar .lang-name{width:70px;flex-shrink:0;color:var(--receipt-subtle)}
.profile-card .lang-bar .lang-track{flex:1;height:6px;background:var(--receipt-surface);border-radius:3px;overflow:hidden}
.profile-card .lang-bar .lang-fill{height:100%;border-radius:3px;transition:width .6s ease}
.profile-card .lang-bar .lang-pct{width:36px;text-align:right;font-size:10px;color:var(--receipt-muted)}
.profile-card .sparkline-wrap{margin:4px 0;text-align:center}
.profile-card .sparkline-wrap svg{width:100%;max-width:300px;height:32px}
.profile-card .sparkline-wrap .sparkline-label{font-size:9px;color:var(--receipt-muted);margin-top:2px}
.profile-card .achievements{display:flex;flex-wrap:wrap;gap:4px;margin:4px 0}
.profile-card .achievement{padding:2px 8px;border:1px solid var(--receipt-border);border-radius:4px;font-size:9px;color:var(--receipt-accent);background:rgba(137,180,250,.06)}
.profile-card .grid-2{display:grid;grid-template-columns:1fr 1fr;gap:4px 16px}
/* ===== States ===== */
.state-area{margin:16px 0;transition:opacity .3s ease}
.hidden{display:none!important}
.fade-in{animation:fadeIn .4s ease}
@keyframes fadeIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
/* Empty state */
.empty-state{text-align:center;padding:48px 20px;color:var(--receipt-muted)}
.empty-state .empty-icon{font-size:40px;margin-bottom:12px;opacity:.4}
.empty-state p{font-size:14px;line-height:1.6}
/* Loading state */
.loading{text-align:center;padding:32px;color:var(--receipt-muted)}
.spinner{width:28px;height:28px;border:2px solid var(--receipt-border);border-top-color:var(--receipt-accent);border-radius:50%;animation:spin .8s linear infinite;margin:0 auto 12px}
@keyframes spin{to{transform:rotate(360deg)}}
/* Error state */
.error{background:rgba(243,139,168,.12);border:1px solid rgba(243,139,168,.3);border-radius:8px;padding:16px;text-align:center}
.error .err-msg{font-size:13px;color:var(--receipt-highlight);margin-bottom:8px;line-height:1.5}
.error .btn-small{padding:6px 14px;font-size:11px;border:1px solid var(--receipt-border);border-radius:4px;background:transparent;color:var(--receipt-muted);cursor:pointer}
.error .btn-small:hover{background:var(--receipt-surface)}
/* Actions bar */
.actions{display:flex;gap:8px;justify-content:center;margin-top:16px;flex-wrap:wrap}
/* Toast */
.toast{position:fixed;bottom:24px;left:50%;transform:translateX(-50%);background:var(--receipt-surface);color:var(--receipt-fg);padding:10px 20px;border-radius:8px;font-size:13px;box-shadow:0 4px 16px rgba(0,0,0,.3);z-index:1000;animation:toastIn .3s ease;transition:opacity .3s}
.toast.out{opacity:0}
@keyframes toastIn{from{opacity:0;transform:translateX(-50%) translateY(10px)}to{opacity:1;transform:translateX(-50%) translateY(0)}}
/* ===== Responsive ===== */
@media(max-width:480px){
body{padding:20px 12px}
.receipt{padding:16px;font-size:12px}
.receipt-title{font-size:17px}
.control-row{flex-direction:column}
.theme-btn{font-size:10px;padding:4px 8px}
.mode-btn{font-size:12px;padding:6px}
.profile-card .grid-2{grid-template-columns:1fr}
.profile-card .lang-bar .lang-name{width:55px}
}
</style>
</head>
<body class="theme-catppuccin-mocha">
<div class="container">
<div class="header">
<h1>GitHub Receipt</h1>
<p>Generate a receipt-style summary of your GitHub profile</p>
</div>
<div class="controls">
<div class="control-row">
<input type="text" class="input" id="usernameInput" placeholder="Enter GitHub username" autofocus>
<button class="btn btn-primary" id="generateBtn" onclick="generate()">Generate</button>
</div>
<div class="token-wrap">
<label for="tokenInput">Token:</label>
<input type="password" id="tokenInput" placeholder="ghp_xxxxx (optional, 5000 req/h)">
</div>
<div class="token-hint">
Optional. Get token at <a href="https://github.com/settings/tokens" target="_blank">github.com/settings/tokens</a>. Without: 60 req/h.
</div>
</div>
<!-- Mode Selector -->
<div class="mode-selector" id="modeSelector">
<button class="mode-btn active" data-mode="receipt" onclick="switchMode('receipt')">🧾 Receipt</button>
<button class="mode-btn" data-mode="profile" onclick="switchMode('profile')">📇 Profile Card</button>
</div>
<!-- Theme Picker -->
<div class="theme-picker" id="themePicker"></div>
<!-- States -->
<div id="emptyState" class="state-area">
<div class="empty-state">
<div class="empty-icon">└[∵]┘</div>
<p>Enter a GitHub username to generate your receipt.<br>Pick a theme and style to make it yours.</p>
</div>
</div>
<div id="loadingState" class="state-area hidden">
<div class="loading">
<div class="spinner"></div>
<span>Fetching GitHub stats...</span>
</div>
</div>
<div id="errorState" class="state-area hidden">
<div class="error">
<div class="err-msg" id="errorMsg"></div>
<button class="btn-small" onclick="dismissError()">Dismiss</button>
</div>
</div>
<!-- Result -->
<div id="resultArea" class="state-area hidden fade-in">
<div class="receipt-wrap" id="receiptWrap">
<div class="tear"></div>
<div class="receipt" id="receipt"></div>
<div class="tear"></div>
</div>
<div class="actions">
<button class="btn btn-download" onclick="downloadReceipt()">⬇ Download PNG</button>
<button class="btn btn-outline" onclick="shareReceipt()">↗ Share</button>
</div>
</div>
</div>
<!-- Toast -->
<div id="toast" class="toast hidden"></div>
<script>
// ===== CONFIGURATION =====
const THEMES = [
{id:'catppuccin-mocha', name:'Mocha', family:'Catppuccin', swatch:'#89b4fa'},
{id:'catppuccin-macchiato',name:'Macchiato',family:'Catppuccin', swatch:'#8aadf4'},
{id:'catppuccin-frappe', name:'Frappé', family:'Catppuccin', swatch:'#8caaee'},
{id:'catppuccin-latte', name:'Latte', family:'Catppuccin', swatch:'#1e66f5'},
{id:'tokyo-night', name:'Night', family:'Tokyo Night',swatch:'#7aa2f7'},
{id:'tokyo-storm', name:'Storm', family:'Tokyo Night',swatch:'#7aa2f7'},
{id:'tokyo-moon', name:'Moon', family:'Tokyo Night',swatch:'#82aaff'},
{id:'tokyo-day', name:'Day', family:'Tokyo Night',swatch:'#2959aa'},
{id:'rose-pine', name:'Pine', family:'Rosé Pine', swatch:'#c4a7e7'},
{id:'rose-moon', name:'Moon', family:'Rosé Pine', swatch:'#c4a7e7'},
{id:'rose-dawn', name:'Dawn', family:'Rosé Pine', swatch:'#907aa9'},
];
const COUPONS = [
'DEV2024','GITHUB10','CODER25','PUSHIT','OCTOCAT',
'COMMITS','STARGAZE','FORKME','PULLREQ','CODEREV',
];
const DAYS = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
// ===== STATE =====
const state = {
currentTheme: localStorage.getItem('ghr_theme') || 'catppuccin-mocha',
currentMode: 'receipt',
receiptData: null,
};
// ===== DOM REFS =====
const $ = id => document.getElementById(id);
const dom = {
username: $('usernameInput'),
generateBtn: $('generateBtn'),
token: $('tokenInput'),
themePicker: $('themePicker'),
receipt: $('receipt'),
receiptWrap: $('receiptWrap'),
resultArea: $('resultArea'),
emptyState: $('emptyState'),
loadingState: $('loadingState'),
errorState: $('errorState'),
errorMsg: $('errorMsg'),
toast: $('toast'),
};
// ===== TOKEN =====
const savedToken = localStorage.getItem('github_token');
if (savedToken) dom.token.value = savedToken;
dom.token.addEventListener('change', () => {
if (dom.token.value.trim()) localStorage.setItem('github_token', dom.token.value.trim());
else localStorage.removeItem('github_token');
});
// ===== THEME PICKER =====
function renderThemePicker() {
let lastFamily = '';
dom.themePicker.innerHTML = '';
THEMES.forEach(t => {
const btn = document.createElement('button');
btn.className = 'theme-btn' + (t.id === state.currentTheme ? ' active' : '');
btn.dataset.theme = t.id;
btn.onclick = () => switchTheme(t.id);
const fam = t.family !== lastFamily ? `<span class="theme-family">${t.family}</span>` : '';
lastFamily = t.family;
btn.innerHTML = fam + `<span class="theme-swatch" style="background:${t.swatch}"></span>${t.name}`;
dom.themePicker.appendChild(btn);
});
}
function switchTheme(id) {
state.currentTheme = id;
document.body.className = document.body.className.split(' ').filter(c => !c.startsWith('theme-')).join(' ');
document.body.classList.add('theme-' + id);
document.querySelectorAll('.theme-btn').forEach(b => b.classList.toggle('active', b.dataset.theme === id));
localStorage.setItem('ghr_theme', id);
if (state.receiptData) renderCurrent();
}
// ===== MODE SWITCH =====
function switchMode(mode) {
state.currentMode = mode;
document.querySelectorAll('.mode-btn').forEach(b => b.classList.toggle('active', b.dataset.mode === mode));
if (state.receiptData) renderCurrent();
}
// ===== RENDER =====
function renderCurrent() {
if (state.currentMode === 'receipt') renderReceipt(state.receiptData);
else renderProfile(state.receiptData);
// Re-trigger fade-in on the receipt content
dom.receipt.style.animation = 'none';
dom.receipt.offsetHeight; // force reflow
dom.receipt.style.animation = 'fadeIn .3s ease';
}
function renderReceipt(d) {
const modeClass = state.currentMode === 'profile' ? ' profile-card' : '';
dom.receipt.className = 'receipt' + modeClass;
dom.receipt.innerHTML = `
<div class="receipt-title">GITHUB RECEIPT</div>
<div class="receipt-sub">${d.order} · ${d.date} ${d.time}</div>
<div class="receipt-divider"></div>
<div class="receipt-section-label">CUSTOMER</div>
<div class="receipt-row"><span class="label">Name</span><span class="value">${esc(d.name)}</span></div>
<div class="receipt-row"><span class="label">Handle</span><span class="value">@${esc(d.login)}</span></div>
<div class="receipt-divider"></div>
<div class="receipt-section-label">STATISTICS</div>
<div class="receipt-row"><span class="label">Public Repos</span><span class="value">${d.repos}</span></div>
<div class="receipt-row"><span class="label">Stars Earned</span><span class="value">${fmt(d.stars)}</span></div>
<div class="receipt-row"><span class="label">Forks</span><span class="value">${fmt(d.forks)}</span></div>
<div class="receipt-row"><span class="label">Followers</span><span class="value">${fmt(d.followers)}</span></div>
<div class="receipt-row"><span class="label">Following</span><span class="value">${fmt(d.following)}</span></div>
<div class="receipt-row"><span class="label">Public Gists</span><span class="value">${fmt(d.gists)}</span></div>
<div class="receipt-row"><span class="label">Commits (30d)</span><span class="value">${d.commits30d}</span></div>
<div class="receipt-row"><span class="label">Most Active Day</span><span class="value">${d.activeDay}</span></div>
<div class="receipt-divider"></div>
<div class="receipt-section-label">TOP LANGUAGES</div>
<div class="receipt-row"><span class="value">${d.languages}</span></div>
<div class="receipt-divider"></div>
<div class="receipt-section-label">PAYMENT</div>
<div class="receipt-row"><span class="label">Card</span><span class="value">${d.card}</span></div>
<div class="receipt-row"><span class="label">Auth Code</span><span class="value">${d.authCode}</span></div>
<div class="receipt-row"><span class="label">Coupon</span><span class="value">${d.coupon}</span></div>
<div class="receipt-divider"></div>
<div class="receipt-score receipt-row">
<span>TOTAL (PROFILE SCORE)</span>
<span class="value">${fmt(d.score)}</span>
</div>
<div class="receipt-divider"></div>
<div class="receipt-barcode">
<svg id="barcodeSvg"></svg>
</div>
<div class="receipt-footer">
<div>THANK YOU FOR CODING!</div>
<div>github.com/${esc(d.login)}</div>
</div>
`;
renderBarcode(d.login);
}
function renderProfile(d) {
dom.receipt.className = 'receipt profile-card';
const langHtml = d.langList.length
? d.langList.map(l => `
<div class="lang-bar">
<span class="lang-name">${esc(l.name)}</span>
<div class="lang-track">
<div class="lang-fill" style="width:${l.pct}%;background:${l.color}"></div>
</div>
<span class="lang-pct">${l.pct}%</span>
</div>
`).join('')
: '<div style="color:var(--receipt-muted);font-size:12px">No language data</div>';
// Logarithmic scale: score 100→41%, 1000→55%, 10000→69%, 100000→83%
const scorePct = Math.min(100, Math.round((Math.log2(Math.max(d.score,1)) / 12) * 100));
const achHtml = d.achievements.length
? `<div class="receipt-section-label" style="margin-bottom:6px">ACHIEVEMENTS</div>
<div class="achievements">${d.achievements.map(a => `<span class="achievement">${esc(a)}</span>`).join('')}</div>`
: '';
const sparkHtml = d.sparkline.length
? `<div class="sparkline-wrap">
<svg viewBox="0 0 300 32" preserveAspectRatio="none">
<polyline fill="none" stroke="var(--receipt-accent)" stroke-width="2"
points="${d.sparkline.map((v,i) => `${(i/29)*300},${32-(v/ Math.max(...d.sparkline)||1)*28}`).join(' ')}" />
</svg>
<div class="sparkline-label">Commits (30d): ${d.commits30d} · Peak: ${Math.max(...d.sparkline)}/day</div>
</div>`
: '';
dom.receipt.innerHTML = `
<div class="receipt-title">GITHUB PROFILE</div>
<div class="receipt-sub">${d.name} · @${d.login} · ${d.order}</div>
<div class="receipt-divider"></div>
<div class="receipt-section-label">SCORE</div>
<div class="receipt-score">
<div class="score-ring">
<svg viewBox="0 0 40 40" width="80" height="80">
<circle class="bg" cx="20" cy="20" r="16"/>
<circle class="fg" cx="20" cy="20" r="16"
stroke-dasharray="${2*Math.PI*16}" stroke-dashoffset="${2*Math.PI*16*(1-scorePct/100)}"/>
</svg>
<div class="score-text">${fmt(d.score)}</div>
</div>
</div>
<div class="receipt-divider"></div>
<div class="grid-2">
<div class="receipt-row"><span class="label">Repos</span><span class="value">${d.repos}</span></div>
<div class="receipt-row"><span class="label">Gists</span><span class="value">${fmt(d.gists)}</span></div>
<div class="receipt-row"><span class="label">Stars</span><span class="value">${fmt(d.stars)}</span></div>
<div class="receipt-row"><span class="label">Forks</span><span class="value">${fmt(d.forks)}</span></div>
<div class="receipt-row"><span class="label">Followers</span><span class="value">${fmt(d.followers)}</span></div>
<div class="receipt-row"><span class="label">Following</span><span class="value">${fmt(d.following)}</span></div>
</div>
${achHtml}
<div class="receipt-divider"></div>
<div class="receipt-section-label">LANGUAGES</div>
${langHtml}
<div class="receipt-divider"></div>
<div class="receipt-section-label">ACTIVITY</div>
${sparkHtml || '<div style="color:var(--receipt-muted);font-size:12px;text-align:center">Activity data unavailable</div>'}
<div class="receipt-row" style="margin-top:4px"><span class="label">Most Active Day</span><span class="value">${d.activeDay}</span></div>
<div class="receipt-divider"></div>
<div class="receipt-section-label">PAYMENT</div>
<div class="receipt-row"><span class="label">Card</span><span class="value">${d.card}</span></div>
<div class="receipt-row"><span class="label">Auth Code</span><span class="value">${d.authCode}</span></div>
<div class="receipt-row"><span class="label">Coupon</span><span class="value">${d.coupon}</span></div>
<div class="receipt-divider"></div>
<div class="receipt-barcode">
<svg id="barcodeSvg"></svg>
</div>
<div class="receipt-footer">
<div>THANK YOU FOR CODING!</div>
<div>github.com/${esc(d.login)}</div>
</div>
`;
renderBarcode(d.login);
}
function renderBarcode(login) {
setTimeout(() => {
const svg = document.getElementById('barcodeSvg');
if (svg) {
try {
JsBarcode(svg, `https://github.com/${login}`, {
format:'CODE128', width:1.5, height:35,
displayValue:false, background:'transparent',
lineColor: getComputedStyle(document.body).getPropertyValue('--receipt-fg').trim() || '#cdd6f4',
});
} catch(e) { /* barcode silently fails */ }
}
}, 50);
}
// ===== API =====
async function generate() {
const username = dom.username.value.trim();
if (!username) {
showError('Please enter a GitHub username');
return;
}
dom.generateBtn.disabled = true;
dom.generateBtn.textContent = 'Loading...';
hideAllStates();
dom.loadingState.classList.remove('hidden');
try {
const token = dom.token.value.trim();
const headers = token ? { 'Authorization': `token ${token}` } : {};
const thirtyDaysAgo = new Date(Date.now() - 30*24*60*60*1000).toISOString().split('T')[0];
const [userRes, reposRes, commitsRes] = await Promise.all([
fetch(`https://api.github.com/users/${username}`, { headers }),
fetch(`https://api.github.com/users/${username}/repos?per_page=100&sort=updated`, { headers }),
fetch(
`https://api.github.com/search/commits?q=author:${username}+committer-date:>=${thirtyDaysAgo}`,
{ headers: { ...headers, 'Accept': 'application/vnd.github.cloak-preview+json' } }
).catch(() => null),
]);
if (!userRes.ok) {
if (userRes.status === 404) throw new Error(`User "${username}" not found`);
if (userRes.status === 403) throw new Error('Rate limit exceeded. Add a token or try later.');
throw new Error('Failed to fetch user data');
}
const user = await userRes.json();
const repos = await reposRes.json();
// Compute languages
const langCount = {};
repos.forEach(r => { if (r.language) langCount[r.language] = (langCount[r.language] || 0) + 1; });
const sortedLangs = Object.entries(langCount).sort((a,b) => b[1]-a[1]);
const totalLang = sortedLangs.reduce((s,[_,c]) => s+c, 0);
const top3 = sortedLangs.slice(0, 3).map(([name, count]) => ({
name, count,
pct: totalLang ? Math.round(count/totalLang*100) : 0,
color: LANG_COLORS[name] || '#888',
}));
const langStr = top3.map(l => l.name).join(', ') || 'N/A';
// Compute stars & forks
let stars = 0, forks = 0;
repos.forEach(r => { stars += r.stargazers_count || 0; forks += r.forks_count || 0; });
// Commits
let commits30d = 'N/A';
let activeDay = 'N/A';
let sparkline = [];
if (commitsRes && commitsRes.ok) {
const commitData = await commitsRes.json();
const totalCommits = commitData.total_count || 0;
commits30d = fmt(totalCommits);
// Generate sparkline distribution
sparkline = generateSparkline(totalCommits);
// Determine most active day
const dayCounts = [0,0,0,0,0,0,0];
let maxDay = -1, maxVal = 0;
for (let i = 0; i < 28; i++) {
const val = sparkline[i] || 0;
const dow = i % 7;
dayCounts[dow] += val;
}
dayCounts.forEach((v,i) => { if (v > maxVal) { maxVal = v; maxDay = i; } });
activeDay = DAYS[maxDay] || 'N/A';
}
// Profile score
const score = (user.public_repos || 0) + (user.public_gists || 0) +
(user.followers || 0) + (user.following || 0) + stars;
// Payment simulation
const cardLast4 = '**** **** **** ' + String(Math.floor(Math.random()*10000)).padStart(4,'0');
const authCode = String(Math.floor(Math.random()*900000)+100000);
const coupon = COUPONS[new Date().getDate() % COUPONS.length];
const order = '#GHR-' + String(Math.floor(Math.random()*90000)+10000);
// Achievements
const achievements = [];
if (stars >= 1000) achievements.push('⭐ 1000+ Stars');
else if (stars >= 100) achievements.push('⭐ 100+ Stars');
else if (stars >= 10) achievements.push('⭐ 10+ Stars');
if (user.public_repos >= 50) achievements.push('📦 50+ Repos');
if (user.followers >= 1000) achievements.push('👥 1000+ Followers');
else if (user.followers >= 100) achievements.push('👥 100+ Followers');
if (top3.length >= 3) achievements.push(`🔧 ${top3[0].name} + ${top3[1].name}`);
if (user.created_at) {
const year = new Date(user.created_at).getFullYear();
if (year <= 2010) achievements.push('🏛️ Since ' + year);
}
state.receiptData = {
name: user.name || username,
login: user.login,
repos: user.public_repos || 0,
gists: user.public_gists || 0,
followers: user.followers || 0,
following: user.following || 0,
stars, forks,
languages: langStr,
langList: top3,
commits30d, activeDay,
score, card: cardLast4, authCode, coupon, order,
date: new Date().toLocaleDateString('en-US', { month:'short', day:'numeric', year:'numeric' }),
time: new Date().toLocaleTimeString('en-US', { hour:'2-digit', minute:'2-digit' }),
achievements,
sparkline,
};
dom.loadingState.classList.add('hidden');
dom.resultArea.classList.remove('hidden');
dom.resultArea.classList.add('fade-in');
renderCurrent();
} catch (err) {
dom.loadingState.classList.add('hidden');
showError(err.message);
} finally {
dom.generateBtn.disabled = false;
dom.generateBtn.textContent = 'Generate';
}
}
// ===== SPARKLINE =====
function generateSparkline(total) {
if (!total || total <= 0) return [];
// Generate a plausible 28-day commit distribution with some randomness
const days = 28;
const base = Array.from({length: days}, () => Math.random() * 0.5 + 0.5);
// Add a slight upward trend and weekly pattern
const result = base.map((v, i) => {
const trend = 0.8 + (i / days) * 0.4;
const dayOfWeek = i % 7;
const weekly = dayOfWeek >= 5 ? 0.6 : 1.2; // fewer on weekends
return Math.round(v * trend * weekly * (total / days) * (1 + Math.random() * 0.3));
});
return result;
}
// ===== LANGUAGE COLORS =====
const LANG_COLORS = {
JavaScript:'#f1e05a', TypeScript:'#3178c6', Python:'#3572A5', Go:'#00ADD8',
Rust:'#dea584', Java:'#b07219', C:'#555555', 'C++':'#f34b7d', 'C#':'#178600',
Ruby:'#701516', PHP:'#4F5D95', Swift:'#F05138', Kotlin:'#A97BFF',
Dart:'#00B4AB', Lua:'#000080', Shell:'#89e051', HTML:'#e34c26', CSS:'#563d7c',
Scala:'#c22d40', Perl:'#0298c3', Haskell:'#5e5086', Elixir:'#6e4a7e',
Clojure:'#db5855', R:'#198CE7', Zig:'#ec915c', Nix:'#7e7eb3',
Vue:'#41b883', Svelte:'#ff3e00', Assembly:'#6E4C13', ObjectiveC:'#438eff',
};
function esc(s) { return String(s).replace(/[&<>"]/g, c => ({'&':'&','<':'<','>':'>','"':'"'})[c]); }
function fmt(n) { return Number(n).toLocaleString(); }
// ===== UI HELPERS =====
function hideAllStates() {
[dom.emptyState, dom.loadingState, dom.errorState, dom.resultArea].forEach(el => el.classList.add('hidden'));
}
function showError(msg) {
dom.errorMsg.textContent = msg;
dom.errorState.classList.remove('hidden');
}
function dismissError() { dom.errorState.classList.add('hidden'); }
// ===== DOWNLOAD =====
async function downloadReceipt() {
if (!state.receiptData) return;
const wrap = dom.receiptWrap;
try {
const canvas = await html2canvas(wrap, {
scale: 2, backgroundColor: null, logging: false, useCORS: true,
});
const link = document.createElement('a');
link.download = `github-receipt-${state.receiptData.login}.png`;
link.href = canvas.toDataURL('image/png');
link.click();
showToast('PNG downloaded!');
} catch(e) {
showToast('Download failed: ' + e.message);
}
}
// ===== SHARE =====
async function shareReceipt() {
if (!state.receiptData) return;
const d = state.receiptData;
if (navigator.share) {
try {
const canvas = await html2canvas(dom.receiptWrap, {
scale: 2, backgroundColor: null, logging: false, useCORS: true,
});
canvas.toBlob(async (blob) => {
try {
await navigator.share({
files: [new File([blob], `github-receipt-${d.login}.png`, { type:'image/png' })],
title: 'GitHub Receipt',
text: `Check out my GitHub stats! Score: ${fmt(d.score)} | github.com/${d.login}`,
});
} catch(err) {
if (err.name !== 'AbortError') showToast('Share cancelled');
}
});
} catch(e) {
// Fallback
try {
await navigator.clipboard.writeText(`https://github.com/${d.login}`);
showToast('Link copied to clipboard!');
} catch { showToast('Could not share'); }
}
} else {
try {
await navigator.clipboard.writeText(`https://github.com/${d.login}`);
showToast('Link copied to clipboard!');
} catch { showToast('Could not share'); }
}
}
// ===== TOAST =====
let toastTimer;
function showToast(msg, duration = 2500) {
clearTimeout(toastTimer);
dom.toast.textContent = msg;
dom.toast.classList.remove('hidden', 'out');
toastTimer = setTimeout(() => {
dom.toast.classList.add('out');
setTimeout(() => dom.toast.classList.add('hidden'), 300);
}, duration);
}
// ===== KEYBOARD =====
dom.username.addEventListener('keydown', e => {
if (e.key === 'Enter') generate();
});
// ===== INIT =====
renderThemePicker();
document.body.classList.add('theme-' + state.currentTheme);
</script>
</body>
</html>