|
41 | 41 | fields.push("Last seen: " + timeDifference(new Date(), lastPlayedParsedUtcDate));
|
42 | 42 | fields.push("Rounds played: " + data.totalRoundsPlayed);
|
43 | 43 | fields.push("Total antag rounds played: " + data.totalAntagRoundsPlayed);
|
44 |
| - let mostPlayedCharacter = data.characters.sort((a, b) => b.roundsPlayed - a.roundsPlayed)[0]; |
45 |
| - fields.push("Most played character: " + mostPlayedCharacter.characterName + " (" + mostPlayedCharacter.roundsPlayed + " rounds)"); |
46 |
| - let mostPlayedJob = data.jobCount.sort((a, b) => b.roundsPlayed - a.roundsPlayed)[0]; |
47 |
| - fields.push("Most played job: " + mostPlayedJob.jobPrototype + " (" + mostPlayedJob.roundsPlayed + " rounds)"); |
| 44 | + if (data.characters.length == 0) { |
| 45 | + fields.push("No character data available"); |
| 46 | + } else { |
| 47 | + let mostAntagCharacter = data.characters.sort((a, b) => b.antagRoundsPlayed - a.antagRoundsPlayed)[0]; |
| 48 | + fields.push("Most antag rounds played: " + mostAntagCharacter.characterName + " (" + mostAntagCharacter.antagRoundsPlayed + " rounds)"); |
| 49 | + } |
| 50 | + if (data.jobCount.length == 0) { |
| 51 | + fields.push("No job data available"); |
| 52 | + } else { |
| 53 | + let mostPlayedJob = data.jobCount.sort((a, b) => b.roundsPlayed - a.roundsPlayed)[0]; |
| 54 | + fields.push("Most played job: " + mostPlayedJob.jobPrototype + " (" + mostPlayedJob.roundsPlayed + " rounds)"); |
| 55 | + } |
48 | 56 |
|
49 | 57 | $("#content-text-" + "@ProfileId").html(fields.join("<br>"));
|
50 | 58 |
|
| 59 | + // Finish loading |
| 60 | + $("#loading-spinner-" + "@ProfileId").addClass("hidden"); |
| 61 | + }, |
| 62 | + error: function(data) { |
| 63 | + console.error(data); |
| 64 | + // if we got a unauthorized response, profile is private |
| 65 | + if (data.status == 401) { |
| 66 | + $("#content-title-" + "@ProfileId").text("Private profile"); |
| 67 | + $("#content-text-" + "@ProfileId").text("This profile is private, you can't see any data."); |
| 68 | + } else { |
| 69 | + $("#content-title-" + "@ProfileId").text("Error"); |
| 70 | + $("#content-text-" + "@ProfileId").text("An error occurred while fetching data."); |
| 71 | + } |
| 72 | + |
51 | 73 | // Finish loading
|
52 | 74 | $("#loading-spinner-" + "@ProfileId").addClass("hidden");
|
53 | 75 | }
|
|
0 commit comments