-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(OpenGuessr): add activity #9398
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0014431
feat(OpenGuessr): add activity
Inkflow59 de001ed
Fixed icon dimensions
Inkflow59 5dea47b
Correction according to ESLint
Inkflow59 4117358
Added stopwatch detection (if any)
Inkflow59 c4ab3d9
Added a console warn if mapTimer = 00:00
Inkflow59 7e16419
Truncate "community_" if present in the category
Inkflow59 abac725
Translation of comments (better understanding)
Inkflow59 761ee67
Removed buttons redirecting to the main page
Inkflow59 c1ebf12
Removing an extra button variable
Inkflow59 368207a
Merge branch 'main' into main
Inkflow59 6fd336c
Removed the last button redirecting to the main page
Inkflow59 cb240e7
Merge branch 'PreMiD:main' into main
Inkflow59 12fbf90
Update metadata.json
Inkflow59 b43ee1f
Removed "iFrameRegExp"
Inkflow59 cc1c695
Removal of unnecessary details
Inkflow59 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,35 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.13", | ||
"apiVersion": 1, | ||
"author": { | ||
"id": "286179374204583938", | ||
"name": "Inkflow" | ||
}, | ||
"service": "OpenGuessr", | ||
"description": { | ||
"de": "OpenGuessr ist eine kostenlose GeoGuessr-Alternative mit unbegrenzten Partien und Multiplayer", | ||
"en": "OpenGuessr is a free GeoGuessr alternative with unlimited play and Multiplayer", | ||
"es": "OpenGuessr es una alternativa gratuita a GeoGuessr con un número ilimitado de partidas y Multijugador", | ||
"fr": "OpenGuessr est une alternative gratuite à GeoGuessr avec un nombre de parties illimité et un mode Multijoueur", | ||
"pt": "OpenGuessr é uma alternativa gratuita a GeoGuessr com um número ilimitado de partidas e Multiplayer" | ||
}, | ||
"url": [ | ||
"openguessr.com", | ||
"www.openguessr.com", | ||
"play.openguessr.com" | ||
], | ||
"regExp": "([a-z0-9-]+[.])*openguessr[.]com[/]", | ||
"version": "1.0.0", | ||
"logo": "https://i.ibb.co/rfxNBp1d/openguessr-icon.png", | ||
"thumbnail": "https://i.imgur.com/Ttplphu.png", | ||
"color": "#f23913", | ||
"category": "games", | ||
"tags": [ | ||
"geography", | ||
"maps", | ||
"guessing", | ||
"geolocation", | ||
"streetview" | ||
], | ||
"readLogs": false | ||
} |
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,168 @@ | ||
import { Assets } from 'premid' | ||
|
||
const presence = new Presence({ | ||
clientId: '1349664981007859754', | ||
}) | ||
const browsingTimestamp = Math.floor(Date.now() / 1000) | ||
|
||
// Update parameters when they are modified | ||
presence.on('UpdateData', async () => { | ||
try { | ||
const presenceData: PresenceData = { | ||
largeImageKey: 'https://i.ibb.co/rfxNBp1d/openguessr-icon.png', | ||
startTimestamp: browsingTimestamp, | ||
} | ||
|
||
// Get current URL | ||
const url = new URL(document.location.href) | ||
const pathname = url.pathname | ||
const fullUrl = url.origin + url.pathname | ||
|
||
// Debug - log the current pathname and full URL to help debugging | ||
console.warn('[OpenGuessr] Current pathname:', pathname) | ||
console.warn('[OpenGuessr] Full URL:', fullUrl) | ||
|
||
if (fullUrl === 'https://openguessr.com/') { | ||
presenceData.details = 'Playing OpenGuessr' | ||
|
||
// Fetch player info | ||
try { | ||
const accountNameElement = document.getElementById('accountName') | ||
const progressRingLevelElement = document.getElementById('progressRingLevel') | ||
|
||
if (accountNameElement && progressRingLevelElement) { | ||
const accountName = accountNameElement.textContent?.trim() | ||
const progressRingLevel = progressRingLevelElement.textContent?.trim() | ||
|
||
if (accountName && progressRingLevel) { | ||
// If it's a guest account (Guest) with level 1, display "Guest mode" | ||
if (accountName === 'Guest' && progressRingLevel === '1') { | ||
presenceData.details = 'Playing OpenGuessr (Guest mode)' | ||
} | ||
else { | ||
presenceData.details = `Playing OpenGuessr (${accountName} | Lv.${progressRingLevel})` | ||
} | ||
} | ||
} | ||
} | ||
catch (e) { | ||
console.error('[OpenGuessr] Error getting player info:', e) | ||
} | ||
|
||
presenceData.state = 'Is guessing' | ||
|
||
// Try to get the selected category and timer from localStorage | ||
try { | ||
const selectedCategory = localStorage.getItem('selectedCategory') | ||
const _singleplayerTimer = localStorage.getItem('singleplayerTimer') | ||
const mapTimer = document.getElementById('mapTimer')?.textContent?.trim() | ||
|
||
// Add category if available | ||
if (selectedCategory) { | ||
// Truncate "community_" if present | ||
let processedCategory = selectedCategory | ||
if (selectedCategory.startsWith('community_')) { | ||
processedCategory = selectedCategory.substring('community_'.length) | ||
} | ||
|
||
// Capitalize the first letter of the category | ||
const capitalizedCategory = processedCategory.charAt(0).toUpperCase() + processedCategory.slice(1) | ||
presenceData.state += ` (${capitalizedCategory})` | ||
} | ||
|
||
// Add remaining time if mapTimer is available and different from "00:00" | ||
if (mapTimer && mapTimer !== '00:00') { | ||
presenceData.state += ` (${mapTimer} remaining)` | ||
console.warn('[OpenGuessr] Map timer found:', mapTimer) | ||
} | ||
else { | ||
console.warn('[OpenGuessr] Map timer not found or is 00:00, not displaying remaining time') | ||
} | ||
} | ||
catch (e) { | ||
console.error('[OpenGuessr] Error getting data from localStorage or timer:', e) | ||
} | ||
|
||
presenceData.smallImageKey = Assets.Play | ||
presenceData.smallImageText = 'In game' | ||
} | ||
else if (fullUrl === 'https://openguessr.com/multiplayer/duel' || fullUrl.startsWith('https://openguessr.com/multiplayer/duel/')) { | ||
presenceData.details = 'Looking for an opponent' | ||
presenceData.smallImageKey = Assets.Search | ||
} | ||
else if (fullUrl === 'https://openguessr.com/multiplayer/host' || fullUrl.startsWith('https://openguessr.com/multiplayer/host/')) { | ||
presenceData.details = 'Hosting a multiplayer game' | ||
presenceData.smallImageKey = Assets.Search | ||
|
||
// Check if a room code is available | ||
try { | ||
const roomCodeElement = document.getElementById('roomCodeDisplay') | ||
if (roomCodeElement && roomCodeElement.textContent) { | ||
const roomCode = roomCodeElement.textContent.trim() | ||
if (roomCode) { | ||
// Add a second button to join the room | ||
presenceData.buttons = [ | ||
{ | ||
label: 'Join the room', | ||
url: `https://openguessr.com/?join=${roomCode}`, | ||
}, | ||
] | ||
console.warn(`[OpenGuessr] Room code found: ${roomCode}, adding join button`) | ||
} | ||
} | ||
} | ||
catch (e) { | ||
console.error('[OpenGuessr] Error getting room code:', e) | ||
} | ||
} | ||
else if (fullUrl === 'https://openguessr.com/multiplayer/join' || fullUrl.startsWith('https://openguessr.com/multiplayer/join/')) { | ||
presenceData.details = 'Joining a multiplayer room' | ||
presenceData.smallImageKey = Assets.Search | ||
} | ||
else if (fullUrl === 'https://openguessr.com/competitions/create' || fullUrl.startsWith('https://openguessr.com/competitions/create/')) { | ||
presenceData.details = 'Creating a competition' | ||
presenceData.smallImageKey = Assets.Search | ||
} | ||
else if (fullUrl === 'https://openguessr.com/leaderboard' || fullUrl.startsWith('https://openguessr.com/leaderboard/')) { | ||
presenceData.details = 'Viewing leaderboard' | ||
presenceData.smallImageKey = Assets.Search | ||
} | ||
else if (fullUrl === 'https://openguessr.com/maps' || fullUrl.startsWith('https://openguessr.com/maps/')) { | ||
presenceData.details = 'Is selecting a game mode' | ||
presenceData.smallImageKey = Assets.Search | ||
} | ||
else if (fullUrl === 'https://openguessr.com/multiplayer' || fullUrl.startsWith('https://openguessr.com/multiplayer/')) { | ||
presenceData.details = 'Wants to play online' | ||
presenceData.smallImageKey = Assets.Search | ||
} | ||
else if (fullUrl === 'https://openguessr.com/competitions' || fullUrl.startsWith('https://openguessr.com/competitions/')) { | ||
presenceData.details = 'Checks for a competition' | ||
presenceData.smallImageKey = Assets.Search | ||
} | ||
else { | ||
presenceData.details = 'Browsing OpenGuessr' | ||
presenceData.smallImageKey = Assets.Reading | ||
} | ||
|
||
// Set activity | ||
presence.setActivity(presenceData) | ||
|
||
// Debug - display in console to help debugging | ||
console.warn('[OpenGuessr] Presence updated:', { | ||
pathname, | ||
presenceData, | ||
hasButtons: presenceData.buttons ? 'Yes' : 'No', | ||
buttonsData: presenceData.buttons, | ||
}) | ||
} | ||
catch (error) { | ||
console.error(`[OpenGuessr] Error in presence: ${error}`) | ||
|
||
// In case of error, display a basic presence | ||
presence.setActivity({ | ||
largeImageKey: 'https://i.ibb.co/rfxNBp1d/openguessr-icon.png', | ||
details: 'Browsing OpenGuessr', | ||
startTimestamp: browsingTimestamp, | ||
}) | ||
} | ||
}) |
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.