Skip to content

Commit

Permalink
Handle CrazyGames user profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Jul 7, 2024
1 parent a111d53 commit 7a4023e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Binary file added public/assets/images/social_crazygames.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions src/geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const express = require('express');
const axios = require('axios');
const router = express.Router();

const PORT = process.env.PORT || 3000;

const IPINFO_TOKEN = process.env.IPINFO_API_TOKEN;

router.get('/', async (req, res) => {
Expand Down
33 changes: 27 additions & 6 deletions src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function escapeHtml(unsafe) {
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
.replace(/'/g, "&#039;");
}

router.get('/:user', function (req, res) {
Expand All @@ -22,11 +22,32 @@ router.get('/:user', function (req, res) {
const userid = req.params.user;

const isSteamUser = userid.startsWith('steam_');
const platformName = isSteamUser ? 'Steam' : 'Discord';
const profileUrl = isSteamUser
? `https://steamcommunity.com/profiles/${userid.split('_')[1]}`
: `https://discord.com/users/${userid.split('_')[1]}`;
const platformIconClass = isSteamUser ? 'fa-brands fa-steam' : 'fa-brands fa-discord';
const isDiscordUser = userid.startsWith('discord_');
const isCrazyGamesUser = userid.startsWith('crazygames_');
let platformName, profileUrl, platformIconClass;

if (isSteamUser) {
platformName = 'Steam';
profileUrl = `https://steamcommunity.com/profiles/${userid.split('_')[1]}`;
platformIconClass = 'fa-brands fa-steam';
}
else if (isDiscordUser) {
platformName = 'Discord';
profileUrl = `https://discord.com/users/${userid.split('_')[1]}`;
platformIconClass = 'fa-brands fa-discord';
}
else if (isCrazyGamesUser) {
platformName = 'CrazyGames';
profileUrl = `https://www.crazygames.com/uid/${userid.split('_')[1]}`;

/* A crazygames image will be used instead */
platformIconClass = '';
}
else {
platformName = 'Unknown';
profileUrl = '#';
platformIconClass = 'fa-question';
}

// Check for associations
let associationType = null;
Expand Down
9 changes: 8 additions & 1 deletion views/user.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
<tr>
<td style="min-width: 150px;">External profile</td>
<td style="min-width: 300px;">
<a href="<%= profileUrl %>" target="_blank"><i class="<%= platformIconClass %>"></i> <%= platformName %><span class="external-link-icon" aria-hidden="true"></span></a>
<a href="<%= profileUrl %>" target="_blank" style="display: flex; align-items: center;">
<% if (platformName === 'CrazyGames') { %>
<img src="/assets/images/social_crazygames.png" alt="CrazyGames" style="width: 1.3em; height: 1.3em; margin-right: 0.3em;">
<% } else { %>
<i class="<%= platformIconClass %>" style="margin-right: 0.3em;"></i>
<% } %>
<%= platformName %><span class="external-link-icon" aria-hidden="true"></span>
</a>
</tr>
<% if (associationType && associatedProfileUrl && associatedId) { %>
<tr>
Expand Down

0 comments on commit 7a4023e

Please sign in to comment.