Skip to content

Commit e581976

Browse files
committed
update: Updated files
1 parent bf86302 commit e581976

File tree

3 files changed

+146
-45
lines changed

3 files changed

+146
-45
lines changed

site/404.html

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,26 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Redirecting... | Testify</title>
77
<script>
8-
// This script helps handle routing
8+
// Handle GitHub Pages routing
99
(function() {
10-
// Split the URL path
1110
const path = window.location.pathname;
12-
const search = window.location.search;
1311

14-
// Check if it's a leaderboard route
15-
if (path.includes('/leaderboard/')) {
16-
const pathParts = path.split('/');
17-
const lastPart = pathParts[pathParts.length - 1];
18-
19-
if (lastPart === 'global') {
20-
// Go to global leaderboard
21-
window.location.href = '/global-leaderboard.html';
22-
} else if (lastPart && lastPart !== 'leaderboard') {
23-
// Store guild ID and redirect to leaderboard page
24-
sessionStorage.setItem('guildId', lastPart);
25-
window.location.href = '/leaderboard.html';
26-
} else {
27-
// Default to home page
28-
window.location.href = '/';
29-
}
30-
} else {
31-
// Default to home page for other routes
32-
window.location.href = '/';
12+
// If looking for the global leaderboard
13+
if (path.endsWith('/leaderboard/global') || path.endsWith('/leaderboard/global/')) {
14+
window.location.href = '/global-leaderboard.html';
15+
return;
3316
}
17+
18+
// If looking for a guild leaderboard
19+
if (path.match(/\/leaderboard\/\d+/)) {
20+
const guildId = path.split('/').pop();
21+
sessionStorage.setItem('guildId', guildId);
22+
window.location.href = '/leaderboard.html';
23+
return;
24+
}
25+
26+
// Default redirect for other paths
27+
window.location.href = '/';
3428
})();
3529
</script>
3630
<style>
@@ -45,6 +39,7 @@
4539
margin: 0;
4640
flex-direction: column;
4741
text-align: center;
42+
padding: 0 1rem;
4843
}
4944
.loader {
5045
border: 5px solid rgba(255, 255, 255, 0.1);
@@ -66,6 +61,7 @@
6661
p {
6762
font-size: 16px;
6863
color: #a0a0a0;
64+
max-width: 400px;
6965
}
7066
</style>
7167
</head>

site/js/global-leaderboard.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,67 @@ document.addEventListener('DOMContentLoaded', function() {
4646
// Functions
4747
async function fetchGlobalLeaderboard(page) {
4848
try {
49-
// Use relative API endpoint
50-
const response = await fetch(`/api/leaderboard/global?page=${page}`);
49+
// Check if running on GitHub Pages (testify.lol)
50+
const isGitHubPages = window.location.hostname.includes('testify.lol') ||
51+
window.location.hostname.includes('github.io');
5152

52-
if (!response.ok) {
53-
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
53+
let data;
54+
55+
if (isGitHubPages) {
56+
// For GitHub Pages, use mock data
57+
data = {
58+
users: generateMockGlobalLeaderboard(50),
59+
pagination: {
60+
totalUsers: 50,
61+
totalPages: 1,
62+
currentPage: 1,
63+
hasNextPage: false,
64+
hasPrevPage: false
65+
}
66+
};
67+
} else {
68+
// For local development with actual API
69+
const response = await fetch(`/api/leaderboard/global?page=${page}`);
70+
71+
if (!response.ok) {
72+
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
73+
}
74+
75+
data = await response.json();
5476
}
5577

56-
const data = await response.json();
5778
renderLeaderboard(data);
5879
} catch (error) {
5980
console.error('Error fetching global leaderboard:', error);
6081
showError(error.message || 'Failed to load global leaderboard data');
6182
}
6283
}
6384

85+
// Generate mock data for GitHub Pages deployment
86+
function generateMockGlobalLeaderboard(count) {
87+
const users = [];
88+
const usernames = [
89+
'Testify', 'DiscordUser', 'GamerPro', 'Kkermit', 'NinjaPlayer',
90+
'ServerBooster', 'LevelMaster', 'XPCollector', 'DiscordNerd',
91+
'BotFan', 'CommandUser', 'PrefixLover', 'SlashMaster', 'TestifyBot',
92+
'LevelGrinder', 'XPFarmer', 'RankChaser', 'TopPlayer', 'DiscordKing',
93+
'BotHelper'
94+
];
95+
96+
for (let i = 0; i < count; i++) {
97+
const randomUsername = usernames[Math.floor(Math.random() * usernames.length)];
98+
users.push({
99+
_id: `1234567890${i.toString().padStart(10, '0')}`,
100+
maxLevel: Math.floor(Math.random() * 100) + 1,
101+
maxXP: Math.floor(Math.random() * 10000) + 1,
102+
guilds: Array(Math.floor(Math.random() * 5) + 1).fill().map(() => `${Math.floor(Math.random() * 1000000000000000000)}`)
103+
});
104+
}
105+
106+
// Sort by level
107+
return users.sort((a, b) => b.maxLevel - a.maxLevel);
108+
}
109+
64110
async function renderLeaderboard(data) {
65111
// Update pagination
66112
currentPage = data.pagination.currentPage;

site/js/leaderboard.js

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ document.addEventListener('DOMContentLoaded', function() {
2828
guildId = sessionStorage.getItem('guildId');
2929
}
3030

31+
// For GitHub Pages demo, use a default guild ID if none is found
32+
if (!guildId && (window.location.hostname.includes('testify.lol') ||
33+
window.location.hostname.includes('github.io'))) {
34+
guildId = '123456789012345678';
35+
}
36+
3137
if (!guildId) {
3238
showError("No guild ID found. Please go back and try again.");
3339
return;
@@ -62,45 +68,98 @@ document.addEventListener('DOMContentLoaded', function() {
6268
});
6369

6470
globalBtn.addEventListener('click', () => {
65-
window.location.href = '/leaderboard/global';
71+
window.location.href = '/global-leaderboard.html';
6672
});
6773

6874
// Functions
6975
async function fetchLeaderboard(page) {
7076
try {
71-
// Use relative API endpoint
72-
const response = await fetch(`/api/leaderboard/${guildId}?page=${page}`);
77+
// Check if running on GitHub Pages (testify.lol)
78+
const isGitHubPages = window.location.hostname.includes('testify.lol') ||
79+
window.location.hostname.includes('github.io');
7380

74-
if (!response.ok) {
75-
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
81+
let data;
82+
83+
if (isGitHubPages) {
84+
// For GitHub Pages, use mock data
85+
data = {
86+
users: generateMockLeaderboard(50),
87+
pagination: {
88+
totalUsers: 50,
89+
totalPages: 1,
90+
currentPage: 1,
91+
hasNextPage: false,
92+
hasPrevPage: false
93+
},
94+
guildId: guildId
95+
};
96+
} else {
97+
// For local development with actual API
98+
const response = await fetch(`/api/leaderboard/${guildId}?page=${page}`);
99+
100+
if (!response.ok) {
101+
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
102+
}
103+
104+
data = await response.json();
76105
}
77106

78-
const data = await response.json();
79107
renderLeaderboard(data);
80108
} catch (error) {
81109
console.error('Error fetching leaderboard:', error);
82110
showError(error.message || 'Failed to load leaderboard data');
83111
}
84112
}
85113

114+
// Generate mock data for GitHub Pages deployment
115+
function generateMockLeaderboard(count) {
116+
const users = [];
117+
const usernames = [
118+
'Testify', 'DiscordUser', 'GamerPro', 'Kkermit', 'NinjaPlayer',
119+
'ServerBooster', 'LevelMaster', 'XPCollector', 'DiscordNerd',
120+
'BotFan', 'CommandUser', 'PrefixLover', 'SlashMaster', 'TestifyBot',
121+
'LevelGrinder', 'XPFarmer', 'RankChaser', 'TopPlayer', 'DiscordKing',
122+
'BotHelper'
123+
];
124+
125+
for (let i = 0; i < count; i++) {
126+
const randomUsername = usernames[Math.floor(Math.random() * usernames.length)];
127+
users.push({
128+
User: `1234567890${i.toString().padStart(10, '0')}`,
129+
Level: Math.floor(Math.random() * 100) + 1,
130+
XP: Math.floor(Math.random() * 10000) + 1,
131+
});
132+
}
133+
134+
// Sort by level
135+
return users.sort((a, b) => b.Level - a.Level);
136+
}
137+
86138
async function renderLeaderboard(data) {
87139
// Update guild info if available
88140
if (data.guildId) {
89-
try {
90-
const discordApiResponse = await fetch(`/api/guild/${data.guildId}`);
91-
if (discordApiResponse.ok) {
92-
const guildData = await discordApiResponse.json();
93-
guildNameEl.textContent = guildData.name || 'Guild Leaderboard';
94-
guildInfoEl.textContent = `${guildData.memberCount || 'Unknown'} members`;
95-
} else {
96-
// Fallback if API call fails
141+
// For GitHub Pages demo, use a mock guild
142+
if (window.location.hostname.includes('testify.lol') ||
143+
window.location.hostname.includes('github.io')) {
144+
guildNameEl.textContent = 'Demo Server Leaderboard';
145+
guildInfoEl.textContent = `${data.users.length} members`;
146+
} else {
147+
try {
148+
const discordApiResponse = await fetch(`/api/guild/${data.guildId}`);
149+
if (discordApiResponse.ok) {
150+
const guildData = await discordApiResponse.json();
151+
guildNameEl.textContent = guildData.name || 'Guild Leaderboard';
152+
guildInfoEl.textContent = `${guildData.memberCount || 'Unknown'} members`;
153+
} else {
154+
// Fallback if API call fails
155+
guildNameEl.textContent = 'Guild Leaderboard';
156+
guildInfoEl.textContent = `Guild ID: ${data.guildId}`;
157+
}
158+
} catch (e) {
159+
console.warn('Could not fetch guild details:', e);
97160
guildNameEl.textContent = 'Guild Leaderboard';
98161
guildInfoEl.textContent = `Guild ID: ${data.guildId}`;
99162
}
100-
} catch (e) {
101-
console.warn('Could not fetch guild details:', e);
102-
guildNameEl.textContent = 'Guild Leaderboard';
103-
guildInfoEl.textContent = `Guild ID: ${data.guildId}`;
104163
}
105164
}
106165

0 commit comments

Comments
 (0)