@@ -19,23 +19,14 @@ document.addEventListener('DOMContentLoaded', function() {
1919 let totalPages = 1 ;
2020 let guildId = '' ;
2121
22- // Extract guild ID from URL or session storage (for GitHub Pages)
23- const getGuildId = ( ) => {
24- // Check if running on GitHub Pages
25- const isGitHubPages = window . location . hostname . includes ( 'github.io' ) ||
26- window . location . hostname . includes ( 'testify.lol' ) ;
27-
28- if ( isGitHubPages ) {
29- // Get guild ID from session storage (set by the routing page)
30- return sessionStorage . getItem ( 'guildId' ) ;
31- } else {
32- // Standard path extraction for development environment
33- const pathParts = window . location . pathname . split ( '/' ) ;
34- return pathParts [ pathParts . length - 1 ] ;
35- }
36- } ;
37-
38- guildId = getGuildId ( ) ;
22+ // Extract guild ID from URL
23+ const pathParts = window . location . pathname . split ( '/' ) ;
24+ guildId = pathParts [ pathParts . length - 1 ] ;
25+
26+ // Also check session storage as fallback
27+ if ( ! guildId || guildId === 'leaderboard.html' ) {
28+ guildId = sessionStorage . getItem ( 'guildId' ) ;
29+ }
3930
4031 if ( ! guildId ) {
4132 showError ( "No guild ID found. Please go back and try again." ) ;
@@ -71,36 +62,14 @@ document.addEventListener('DOMContentLoaded', function() {
7162 } ) ;
7263
7364 globalBtn . addEventListener ( 'click' , ( ) => {
74- // Handle GitHub Pages routing
75- if ( window . location . hostname . includes ( 'github.io' ) ||
76- window . location . hostname . includes ( 'testify.lol' ) ) {
77- window . location . href = '/leaderboard/global' ;
78- } else {
79- window . location . href = '/leaderboard/global' ;
80- }
65+ window . location . href = '/leaderboard/global' ;
8166 } ) ;
8267
83- // API endpoint handling for GitHub Pages
84- function getApiEndpoint ( endpoint ) {
85- // Check if running on GitHub Pages
86- const isGitHubPages = window . location . hostname . includes ( 'github.io' ) ||
87- window . location . hostname . includes ( 'testify.lol' ) ;
88-
89- if ( isGitHubPages ) {
90- // For GitHub Pages, use the mock data endpoint
91- return `https://api.testify.lol${ endpoint } ` ;
92- } else {
93- // For local development
94- return endpoint ;
95- }
96- }
97-
9868 // Functions
9969 async function fetchLeaderboard ( page ) {
10070 try {
101- const apiUrl = getApiEndpoint ( `/api/leaderboard/${ guildId } ?page=${ page } ` ) ;
102-
103- const response = await fetch ( apiUrl ) ;
71+ // Use relative API endpoint
72+ const response = await fetch ( `/api/leaderboard/${ guildId } ?page=${ page } ` ) ;
10473
10574 if ( ! response . ok ) {
10675 throw new Error ( `Server returned ${ response . status } : ${ response . statusText } ` ) ;
@@ -118,7 +87,7 @@ document.addEventListener('DOMContentLoaded', function() {
11887 // Update guild info if available
11988 if ( data . guildId ) {
12089 try {
121- const discordApiResponse = await fetch ( getApiEndpoint ( `/api/guild/${ data . guildId } ` ) ) ;
90+ const discordApiResponse = await fetch ( `/api/guild/${ data . guildId } ` ) ;
12291 if ( discordApiResponse . ok ) {
12392 const guildData = await discordApiResponse . json ( ) ;
12493 guildNameEl . textContent = guildData . name || 'Guild Leaderboard' ;
@@ -157,7 +126,7 @@ document.addEventListener('DOMContentLoaded', function() {
157126 // Try to fetch user info from Discord API
158127 let userInfo ;
159128 try {
160- const userResponse = await fetch ( getApiEndpoint ( `/api/user/${ user . User } ` ) ) ;
129+ const userResponse = await fetch ( `/api/user/${ user . User } ` ) ;
161130 if ( userResponse . ok ) {
162131 userInfo = await userResponse . json ( ) ;
163132 }
0 commit comments