Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions websites/R/RetroAchievements/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://schemas.premid.app/metadata/1.16",
"apiVersion": 1,
"author": {
"id": "961292362208919582",
"name": "jethi_"
},
"service": "RetroAchievements",
"description": {
"en": "RetroAchievements is a platform for tracking and earning achievements in retro video games."
},
"url": "retroachievements.org",
"regExp": "^https?[:][/][/]([a-z0-9-]+[.])*retroachievements[.]org[/]",
"version": "1.0.0",
"logo": "https://i.imgur.com/dFegUxW.png",
"thumbnail": "https://i.imgur.com/xuvJ8sD.png",
"color": "#1065df",
"category": "games",
"tags": [
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
"ra",
"achievements",
"games",
"gaming",
"leaderboards",
"retro",
"tracker"
]
}
98 changes: 98 additions & 0 deletions websites/R/RetroAchievements/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Assets } from 'premid'

const presence = new Presence({
clientId: '1496589220515680326',
})

const browsingTimestamp = Math.floor(Date.now() / 1000)

presence.on('UpdateData', async () => {
const pathname = document.location.pathname
const strings = await presence.getStrings({
buttonViewProfile: 'general.buttonViewProfile',
buttonViewGame: 'general.buttonViewGame',
})

const presenceData: PresenceData = {
largeImageKey: 'https://i.imgur.com/dFegUxW.png',
startTimestamp: browsingTimestamp,
}

// Home
if (pathname === '/' || pathname === '') {
presenceData.details = 'Homepage'
}
// Achievement page
else if (pathname.includes('/achievement/')) {
const achievementTitle = document.querySelector('p[class*="pb-[3px]"]')?.textContent?.trim()
|| document.querySelector('h1')?.textContent?.trim()
|| document.querySelector('.pagetitle')?.textContent?.trim()
|| document.title.split(' - ')[0]?.trim()
presenceData.details = 'Viewing Achievement'
presenceData.state = achievementTitle || 'Achievement Details'
presenceData.buttons = [{ label: 'View Achievement', url: document.location.href }]
}
// Game page
else if (pathname.includes('/game/')) {
const gameTitle = document.querySelector('h1')?.textContent?.trim()
|| document.querySelector('.pagetitle')?.textContent?.trim()
presenceData.details = 'Viewing Game'
presenceData.state = gameTitle || 'Game Page'
presenceData.buttons = [{ label: strings.buttonViewGame, url: document.location.href }]
}
// User profile
else if (pathname.includes('/user/')) {
const usernameFromUrl = pathname.split('/user/')[1]?.split('/')[0]
const usernameFromPage = document.querySelector('h1')?.textContent?.trim()
|| document.querySelector('.username')?.textContent?.trim()
const username = usernameFromPage || usernameFromUrl
presenceData.details = 'Viewing User Profile'
presenceData.state = username ? decodeURIComponent(username) : 'User Profile'
presenceData.buttons = [{ label: strings.buttonViewProfile, url: document.location.href }]
}
// Games list / System games
else if (pathname.startsWith('/games')
|| (pathname.includes('/system/') && pathname.includes('/games'))) {
const searchQuery = new URL(document.location.href).searchParams.get('filter[title]')
if (searchQuery) {
presenceData.details = 'Searching for Games'
presenceData.state = searchQuery
presenceData.smallImageKey = Assets.Search
}
else {
presenceData.details = 'Browsing Games'
}
}
// Forums
else if (pathname === '/forum.php' || pathname.startsWith('/viewforum.php')) {
presenceData.details = 'In Forums'
}
// Settings
else if (pathname.includes('/settings')) {
presenceData.details = 'Managing Account'
}
// Downloads
else if (pathname.includes('/downloads')) {
presenceData.details = 'Viewing Emulators'
}
// Hubs
else if (pathname === '/hubs' || pathname.match(/\/hub\/\d+/)) {

Check failure

Code scanning / ESLint

prefer `RegExp.test()` over `String.match()` and `RegExp.exec()` when only checking for match existence Error

Prefer /\/hub\/\d+/.test(pathname) over pathname.match(/\/hub\/\d+/) for boolean checks
if (pathname === '/hubs') {
presenceData.details = 'Viewing Hubs'
}
else {
presenceData.details = 'Viewing a Hub'
// TODO: - Add button to view hub
// - state should be the hub title
Comment thread
theusaf marked this conversation as resolved.
}
}
// Default fallback
else {
presenceData.details = 'Browsing RetroAchievements'
}

if (presenceData.details)
presence.setActivity(presenceData)
else
presence.clearActivity()
})
Loading