@@ -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