-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(RetroAchievements): add activity #10705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JethiYippee
wants to merge
3
commits into
PreMiD:main
Choose a base branch
from
JethiYippee:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": [ | ||
| "ra", | ||
| "achievements", | ||
| "games", | ||
| "gaming", | ||
| "leaderboards", | ||
| "retro", | ||
| "tracker" | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 failureCode 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 | ||
|
theusaf marked this conversation as resolved.
|
||
| } | ||
| } | ||
| // Default fallback | ||
| else { | ||
| presenceData.details = 'Browsing RetroAchievements' | ||
| } | ||
|
|
||
| if (presenceData.details) | ||
| presence.setActivity(presenceData) | ||
| else | ||
| presence.clearActivity() | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.