forked from DishpitDev/Slopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaderboard.html
632 lines (573 loc) · 22.7 KB
/
leaderboard.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Commit Leaderboard</title>
<style>
body::after {
content: "";
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: repeating-linear-gradient(
0deg,
rgba(0, 0, 0, 0.15),
rgba(0, 0, 0, 0.15) 1px,
transparent 1px,
transparent 2px
);
pointer-events: none;
z-index: 999;
}
.container {
/* ... existing styles ... */
animation: borderPulse 2s infinite;
}
@keyframes borderPulse {
0% { box-shadow: 0 0 15px var(--accent); }
50% { box-shadow: 0 0 25px var(--accent); }
100% { box-shadow: 0 0 15px var(--accent); }
}
:root {
--bg-primary: #000000;
--bg-secondary: #220033;
--text-primary: #00ff00;
--text-secondary: #ff00ff;
--accent: #00ffff;
--border: #ff00ff;
}
body {
margin: 0;
padding: 0;
font-family: 'Press Start 2P', cursive;
background: var(--bg-primary);
color: var(--text-primary);
background-image:
linear-gradient(0deg, transparent 24%,
rgba(32, 255, 255, .05) 25%,
rgba(32, 255, 255, .05) 26%, transparent 27%, transparent 74%,
rgba(32, 255, 255, .05) 75%,
rgba(32, 255, 255, .05) 76%, transparent 77%, transparent),
linear-gradient(90deg, transparent 24%,
rgba(32, 255, 255, .05) 25%,
rgba(32, 255, 255, .05) 26%, transparent 27%, transparent 74%,
rgba(32, 255, 255, .05) 75%,
rgba(32, 255, 255, .05) 76%, transparent 77%, transparent);
background-size: 50px 50px;
text-shadow: 2px 2px #ff00ff;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
border: 2px solid var(--accent);
box-shadow: 0 0 20px var(--accent);
margin-top: 20px;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
border-bottom: 2px solid var(--accent);
padding-bottom: 20px;
}
.header h1 {
font-size: 24px;
color: var(--accent);
text-transform: uppercase;
}
.search-box {
width: 96.5%;
padding: 12px;
margin-bottom: 20px;
background: var(--bg-secondary);
border: 2px solid var(--accent);
color: var(--accent);
font-family: 'Press Start 2P', cursive;
font-size: 12px;
}
.commit-card {
background: var(--bg-secondary);
border: 2px solid var(--accent);
padding: 16px;
margin-bottom: 16px;
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.3s;
box-shadow: 4px 4px 0 var(--border);
}
.commit-card:hover {
transform: translate(-2px, -2px);
box-shadow: 6px 6px 0 var(--border);
}
.commit-info h3 {
font-size: 14px;
margin: 0 0 12px 0;
color: var(--accent);
}
.commit-info p {
font-size: 10px;
color: var(--text-secondary);
}
.upvote-btn {
background: linear-gradient(
45deg,
var(--bg-primary) 0%,
#330066 50%,
var(--bg-primary) 100%
);
border: 2px solid var(--accent);
color: var(--accent);
padding: 8px 16px;
cursor: pointer;
transition: all 0.2s;
font-family: 'Press Start 2P', cursive;
min-width: 80px;
height: 36px;
box-shadow: 3px 3px 0 var(--border);
}
.upvote-btn:hover {
background: var(--accent);
color: var(--bg-primary);
transform: translate(-2px, -2px);
box-shadow: 5px 5px 0 var(--border);
}
.upvote-btn.voted {
background: var(--accent);
color: var(--bg-primary);
}
.auth-button {
background: linear-gradient(
45deg,
var(--bg-primary) 0%,
#330066 50%,
var(--bg-primary) 100%
);
color: var(--accent);
border: 2px solid var(--accent);
padding: 10px 20px;
cursor: pointer;
font-family: 'Press Start 2P', cursive;
font-size: 12px;
box-shadow: 3px 3px 0 var(--border);
transition: all 0.2s;
}
.auth-button:hover {
transform: translate(-2px, -2px);
box-shadow: 5px 5px 0 var(--border);
}
.user-info {
color: var(--text-secondary);
font-size: 12px;
}
#error-message {
background: #ff0000;
color: white;
padding: 10px;
margin-bottom: 20px;
display: none;
border: 2px solid white;
text-align: center;
font-size: 12px;
}
.commit-card .commit-link {
text-decoration: none;
color: inherit;
display: block; /* Makes the entire content area clickable */
}
</style>
</head>
<body>
<div class="container">
<!-- This is the header div -->
<div class="header" style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; border-bottom: 2px solid #00ffff; padding-bottom: 20px;">
<h1 style="font-size: 24px; color: #00ffff; text-transform: uppercase; margin: 0;">Commit Leaderboard</h1>
<div id="auth-section">
<button id="login-button" style="background: #000000; color: #00ffff; border: 2px solid #00ffff; padding: 10px 20px; cursor: pointer; font-family: 'Press Start 2P', cursive; font-size: 12px; box-shadow: 3px 3px 0 #ff00ff; transition: all 0.2s;">Login with GitHub</button>
<span id="user-info" style="color: #ff00ff; font-size: 12px; display: none;"></span>
</div>
</div>
<!-- Add the style switcher buttons here, right after the header -->
<div style="margin-bottom: 20px; text-align: center; padding: 10px; border: 2px solid #00ffff; background: #220033;">
<p class="style_text" style="color: #00ffff; margin-bottom: 10px; font-size: 12px;">SELECT YOUR STYLE</p>
<button onclick="setStyle('synthwave')" style="margin: 0 10px; background: #000000; color: #00ffff; border: 2px solid #00ffff; padding: 8px 16px; cursor: pointer; font-family: 'Press Start 2P', cursive; font-size: 10px; box-shadow:3px 3px 0 #ff00ff;">SYNTHWAVE</button>
<button onclick="setStyle('retroblog')" style="margin: 0 10px; background: #000000; color: #00ffff; border: 2px solid #00ffff; padding: 8px 16px; cursor: pointer; font-family: 'Press Start 2P', cursive; font-size: 10px; box-shadow:3px 3px 0 #ff00ff">RETRO BLOG</button>
<button onclick="setStyle('cyberpunk')" style="margin: 0 10px; background: #000000; color: #00ffff; border: 2px solid #00ffff; padding: 8px 16px; cursor: pointer; font-family: 'Press Start 2P', cursive; font-size: 10px; box-shadow:3px 3px 0 #ff00ff">BASIC</button>
</div>
<div id="error-message" style="background: #ff0000; color: white; padding: 10px; margin-bottom: 20px; display: none; border: 2px solid white; text-align: center; font-size: 12px;"></div>
<input type="text" id="search-input" style="width: 100%; padding: 12px; margin-bottom: 20px; background: #220033; border: 2px solid #00ffff; color: #00ffff; font-family: 'Press Start 2P', cursive; font-size: 12px; box-sizing: border-box;" placeholder="Search commits...">
<div id="leaderboard"></div>
</div>
<script src="lbtunnel.js"></script>
<script>
const CLIENT_ID = 'Ov23ligs3nFJsyC12uPP';
const TUNNEL_URL = 'https://climbing-dane-hip.ngrok-free.app';
let currentTheme = 'synthwave';
let accessToken = localStorage.getItem('github_token');
let votedCommits = new Set(JSON.parse(localStorage.getItem('voted_commits') || '[]'));
// Configure tunnel
tunnel.setBaseUrl(TUNNEL_URL);
// GitHub OAuth login
document.getElementById('login-button').addEventListener('click', () => {
const redirectUri = `${window.location.origin}/leaderboard.html`;
window.location.href = `https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${redirectUri}&scope=read:user`;
});
// Handle OAuth callback
const code = new URLSearchParams(window.location.search).get('code');
if (code) {
tunnel.get(`/auth/github?code=${code}`)
.then(response => {
accessToken = response.access_token;
localStorage.setItem('github_token', accessToken);
// Remove code from URL
window.history.replaceState({}, document.title, '/leaderboard.html');
updateAuthUI();
syncCommits();
})
.catch(error => {
showError(error.message);
console.log(error);
});
}
function updateAuthUI() {
if (accessToken) {
document.getElementById('login-button').style.display = 'none';
document.getElementById('user-info').style.display = 'inline';
// Get user info from GitHub
fetch('https://api.github.com/user', {
headers: { 'Authorization': `token ${accessToken}` }
})
.then(res => res.json())
.then(user => {
document.getElementById('user-info').textContent = `Logged in as ${user.login}`;
});
}
}
function syncCommits() {
tunnel.post('/api/sync', { token: accessToken })
.then(() => loadCommits())
.catch(() => showError('WELCOME TO THE LEADERBOARD'));
}
function showError(message) {
const errorDiv = document.getElementById('error-message');
errorDiv.textContent = message;
if (message === 'WELCOME TO THE LEADERBOARD') {
errorDiv.style.backgroundColor = 'green';
} else {
errorDiv.style.backgroundColor = 'red';
}
errorDiv.style.display = 'block';
setTimeout(() => {
errorDiv.style.display = 'none';
}, 5000);
}
function createCommitCard(commit) {
const card = document.createElement('div');
card.className = 'commit-card';
card.innerHTML = `
<a href="${commit.link}" target="_blank" class="commit-link">
<div class="commit-info">
<h3>${commit.message}</h3>
<p>by ${commit.author} • ${new Date(commit.date).toLocaleDateString()}</p>
</div>
</a>
<button class="upvote-btn ${votedCommits.has(commit.id) ? 'voted' : ''}"
data-commit-id="${commit.id}">
▲ ${commit.upvotes || 0}
</button>`;
//setStyle(currentTheme);
return card;
}
async function loadCommits(searchTerm = '') {
try {
const commits = await tunnel.get('/api/commits', { search: searchTerm });
const leaderboard = document.getElementById('leaderboard');
leaderboard.innerHTML = '';
commits.forEach(commit => {
leaderboard.appendChild(createCommitCard(commit));
});
} catch (error) {
showError('Failed to load commits');
}
finally {
setStyle(currentTheme);
}
}
// Handle voting
document.getElementById('leaderboard').addEventListener('click', async (e) => {
if (!e.target.classList.contains('upvote-btn')) return;
if (!accessToken) {
showError('Please login to vote');
return;
}
const commitId = e.target.dataset.commitId;
if (votedCommits.has(commitId)) return;
try {
await tunnel.post('/api/votes', {
commitId,
userId: accessToken // Using token as userId
});
votedCommits.add(commitId);
localStorage.setItem('voted_commits', JSON.stringify([...votedCommits]));
e.target.classList.add('voted');
const currentVotes = parseInt(e.target.innerText.split('▲')[1]);
e.target.innerText = `▲ ${currentVotes + 1}`;
} catch (error) {
showError('Failed to vote');
}
});
// Handle search
let searchTimeout;
document.getElementById('search-input').addEventListener('input', (e) => {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
loadCommits(e.target.value.trim());
}, 300);
});
// Initial load
updateAuthUI();
loadCommits();
</script>
<script>
const styles = {
synthwave: {
body: {
background: '#000000',
color: '#00ff00',
backgroundImage: `linear-gradient(0deg, transparent 24%,
rgba(32, 255, 255, .05) 25%,
rgba(32, 255, 255, .05) 26%, transparent 27%, transparent 74%,
rgba(32, 255, 255, .05) 75%,
rgba(32, 255, 255, .05) 76%, transparent 77%, transparent),
linear-gradient(90deg, transparent 24%,
rgba(32, 255, 255, .05) 25%,
rgba(32, 255, 255, .05) 26%, transparent 27%, transparent 74%,
rgba(32, 255, 255, .05) 75%,
rgba(32, 255, 255, .05) 76%, transparent 77%, transparent)`,
backgroundSize: '50px 50px',
textShadow: '2px 2px #ff00ff'
},
headerBorder: '#00ffff',
container: {
border: '2px solid #00ffff',
boxShadow: '0 0 20px #00ffff'
},
card: {
background: '#220033',
border: '2px solid #00ffff',
boxShadow: '4px 4px 0 #ff00ff'
},
button: {
background: 'linear-gradient(45deg, #000000 0%, #330066 50%, #000000 100%)',
color: '#00ffff',
border: '2px solid #00ffff',
boxShadow: '3px 3px 0 #ff00ff'
},
buttonHover: {
background: 'linear-gradient(45deg, #00ffff 0%, #0099ff 50%, #00ffff 100%)',
color: '#000000'
},
heading: {
color: '#00ffff'
},
searchBox: {
background: '#220033',
border: '2px solid #00ffff',
color: '#00ffff'
},
styleSwitch: {
background: '#220033',
border: '2px solid #00ffff'
},
commitinfo: {
color: '#ff00ff'
},
userinfo: {
color: '#ff00ff'
},
votedButton: {
background: 'linear-gradient(45deg, #00ffff 0%, #00ccff 50%, #00ffff 100%)',
color: '#000000'
}
},
retroblog: {
body: {
background: '#ffffe0',
color: '#000000',
backgroundImage: `linear-gradient(#ffffe0 2px, transparent 2px),
linear-gradient(90deg, #ffffe0 2px, transparent 2px),
linear-gradient(#d4d4c7 1px, transparent 1px),
linear-gradient(90deg, #d4d4c7 1px, transparent 1px)`,
backgroundSize: '100px 100px, 100px 100px, 20px 20px, 20px 20px',
textShadow: 'none'
},
headerBorder: '#8b4513',
container: {
border: '2px solid #8b4513',
boxShadow: '5px 5px 0 #d2691e'
},
card: {
background: '#ffffff',
border: '1px solid #8b4513',
boxShadow: '3px 3px 0 #d2691e'
},
button: {
background: 'linear-gradient(45deg, #f4a460 0%, #d2691e 50%, #f4a460 100%)',
color: '#000000',
border: '2px solid #8b4513',
boxShadow: '2px 2px 0 #8b4513'
},
buttonHover: {
background: 'linear-gradient(45deg, #d2691e 0%, #8b4513 50%, #d2691e 100%)',
color: '#ffffff'
},
votedButton: {
background: 'linear-gradient(45deg, #8b4513 0%, #654321 50%, #8b4513 100%)',
color: '#ffffff'
},
heading: {
color: '#8b4513'
},
searchBox: {
background: '#ffffff',
border: '2px solid #8b4513',
color: '#000000'
},
styleSwitch: {
background: '#f4a460',
border: '2px solid #8b4513'
},
commitinfo: {
color: '#000000'
},
userinfo: {
color: '#8b4513'
},
},
cyberpunk: {
body: {
background: '#000000',
color: '#33ff33',
backgroundImage: `linear-gradient(
0deg,
rgba(51, 255, 51, 0.03) 50%,
transparent 50%
)`,
backgroundSize: '4px 4px',
textShadow: 'none'
},
headerBorder: '#33ff33',
container: {
border: '1px solid #33ff33',
boxShadow: 'none'
},
card: {
background: '#000000',
border: '1px solid #33ff33',
boxShadow: 'none'
},
button: {
background: 'linear-gradient(45deg, #000000 0%, #001100 50%, #000000 100%)',
color: '#33ff33',
border: '1px solid #33ff33',
boxShadow: 'none'
},
buttonHover: {
background: 'linear-gradient(45deg, #33ff33 0%, #00ff00 50%, #33ff33 100%)',
color: '#000000'
},
votedButton: {
background: 'linear-gradient(45deg, #33ff33 0%, #00cc00 50%, #33ff33 100%)',
color: '#000000'
},
heading: {
color: '#33ff33'
},
searchBox: {
background: '#000000',
border: '1px solid #33ff33',
color: '#33ff33',
boxShadow: 'none'
},
styleSwitch: {
background: '#000000',
border: '1px solid #33ff33',
boxShadow: 'none'
},
commitinfo: {
color: '#ffffff'
},
userinfo: {
color: '#33ff33'
},
}
};
function setStyle(theme) {
currentTheme = theme;
const style = styles[theme];
const userinfo = document.querySelector('#user-info');
Object.assign(userinfo.style, style.userinfo);
document.documentElement.style.setProperty('--button-gradient', style.button.background);
document.documentElement.style.setProperty('--button-hover-gradient', style.buttonHover.background);
document.documentElement.style.setProperty('--button-hover-color', style.buttonHover.color);
document.documentElement.style.setProperty('--voted-gradient', style.votedButton.background);
document.documentElement.style.setProperty('--voted-color', style.votedButton.color);
document.documentElement.style.setProperty('--border', style.button.boxShadow.split(' ')[3]);
// Apply body styles
Object.assign(document.body.style, style.body);
// Apply container styles
const container = document.querySelector('.container');
Object.assign(container.style, style.container);
const header = document.querySelector('.header');
header.style.borderBottom = `2px solid ${style.headerBorder}`
// Apply styles to all cards
document.querySelectorAll('.commit-card').forEach(card => {
Object.assign(card.style, style.card);
});
// Apply styles to all buttons
document.querySelectorAll('button').forEach(button => {
Object.assign(button.style, style.button);
});
document.querySelectorAll('.upvote-btn.voted').forEach(button => {
Object.assign(button.style, style.votedButton);
});
document.querySelectorAll('.upvote-btn').forEach(button => {
if (!button.classList.contains('voted')) {
button.addEventListener('mouseover', () => {
Object.assign(button.style, style.buttonHover);
});
button.addEventListener('mouseout', () => {
Object.assign(button.style, style.button);
});
}
});
// Apply styles to headings
document.querySelectorAll('h1, h3').forEach(heading => {
Object.assign(heading.style, style.heading);
});
// Apply styles to search box
const searchBox = document.querySelector('#search-input');
Object.assign(searchBox.style, style.searchBox);
// Apply styles to style switcher container
const styleSwitch = document.querySelector('[style*="text-align: center"]');
Object.assign(styleSwitch.style, style.styleSwitch);
const styletext = document.querySelector('.style_text');
Object.assign(styletext.style, style.heading);
const commitinfo = document.querySelectorAll('.commit-info p');
commitinfo.forEach(info => {
Object.assign(info.style, style.commitinfo);
});
e.target.classList.add('voted');
Object.assign(e.target.style, styles[currentTheme].votedButton);
// Update createCommitCard function to use current theme
window.currentTheme = theme;
}
</script>
</body>
</html>