Skip to content

Commit 25df5d0

Browse files
authored
feat(Openplace): add activity (#10376)
1 parent 3725231 commit 25df5d0

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

websites/O/OpenPlace/metadata.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "https://schemas.premid.app/metadata/1.16",
3+
"apiVersion": 1,
4+
"author": {
5+
"id": "1120490012153237544",
6+
"name": "Katsu"
7+
},
8+
"service": "OpenPlace",
9+
"description": {
10+
"en": "openplace is a collaborative, real-time pixel canvas layered over the world map, where anyone can paint and create art together."
11+
},
12+
"url": "openplace.live",
13+
"regExp": "^https?[:][/][/]([a-z0-9-]+[.])*openplace[.]live[/]",
14+
"version": "1.0.0",
15+
"logo": "https://i.imgur.com/POz1IBa.png",
16+
"thumbnail": "https://i.imgur.com/a0Myl9w.png",
17+
"color": "#2e5cf1",
18+
"category": "games",
19+
"tags": [
20+
"place",
21+
"redditplace",
22+
"game"
23+
],
24+
"settings": [
25+
{
26+
"id": "coordinatesPrivacy",
27+
"title": "Hide Coordinates",
28+
"icon": "fad fa-user-secret",
29+
"value": false
30+
},
31+
{
32+
"id": "countryPrivacy",
33+
"title": "Hide Country",
34+
"icon": "fad fa-user-secret",
35+
"value": false,
36+
"if": {
37+
"coordinatesPrivacy": true
38+
}
39+
}
40+
]
41+
}

websites/O/OpenPlace/presence.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const presence = new Presence({
2+
clientId: '1460179756770263072',
3+
})
4+
const browsingTimestamp = Math.floor(Date.now() / 1000)
5+
6+
enum ActivityAssets {
7+
Logo = 'https://i.imgur.com/POz1IBa.png',
8+
}
9+
10+
let level: string = 'Unknown'
11+
let pixelsPainted: string = 'Unknown'
12+
13+
function updateGlobals() {
14+
const levelValue = document.querySelector('div.text-primary-content')?.textContent ?? 'Unknown'
15+
if (levelValue !== 'Unknown')
16+
level = levelValue
17+
18+
let pixelsValue = document.querySelector('div.flex.items-center.gap-1 span.text-primary.font-semibold:not(.text-base)')?.textContent ?? 'Unknown'
19+
if (pixelsValue.startsWith('('))
20+
pixelsValue = 'Unknown'
21+
if (pixelsValue !== 'Unknown')
22+
pixelsPainted = pixelsValue
23+
}
24+
25+
presence.on('UpdateData', async () => {
26+
const coordinatesPrivacy = await presence.getSetting<boolean>('coordinatesPrivacy')
27+
const countryPrivacy = !coordinatesPrivacy ? false : await presence.getSetting<boolean>('countryPrivacy')
28+
29+
updateGlobals()
30+
const presenceData: PresenceData = {
31+
largeImageKey: ActivityAssets.Logo,
32+
startTimestamp: browsingTimestamp,
33+
}
34+
35+
const coordinatesElement = document.querySelector('.whitespace-nowrap')
36+
const coordinates = coordinatesElement && coordinatesElement.textContent
37+
? coordinatesElement.textContent.replace('Pixel: ', '')
38+
: 'Unknown'
39+
const zone = document.querySelector('button.btn.btn-xs.flex')?.textContent ?? 'Unknown'
40+
const loggedIn = !document.querySelector('button.btn.btn-primary.shadow-xl')
41+
const isPainting = !!document.querySelector('div.absolute.bottom-0.left-0.z-50.w-full')
42+
43+
// Helper function to determine the state message
44+
const getState = (): string => {
45+
if (!loggedIn)
46+
return 'Logged out'
47+
if (pixelsPainted === 'Unknown')
48+
return level === 'Unknown' ? '' : `Level ${level}`
49+
return `${pixelsPainted} Pixels painted (level ${level})`
50+
}
51+
52+
// Set presence details and state based on available data
53+
if (coordinates === 'Unknown') {
54+
if (level === 'Unknown') {
55+
presenceData.details = !loggedIn ? 'Looking at the map' : 'Placing pixels'
56+
if (loggedIn)
57+
presenceData.state = getState()
58+
}
59+
else {
60+
presenceData.details = !isPainting ? 'Looking at the map' : 'Placing pixels'
61+
presenceData.state = getState()
62+
}
63+
}
64+
else {
65+
if (coordinatesPrivacy) {
66+
if (countryPrivacy) {
67+
presenceData.details = `Viewing a pixel`
68+
}
69+
else {
70+
presenceData.details = zone === 'Unknown'
71+
? `Viewing a pixel`
72+
: `Viewing a pixel in ${zone}`
73+
}
74+
}
75+
else {
76+
presenceData.details = zone === 'Unknown'
77+
? `Looking at pixel ${coordinates} (Unknown zone)`
78+
: `Looking at pixel ${coordinates} (${zone})`
79+
}
80+
presenceData.state = getState()
81+
}
82+
83+
presence.setActivity(presenceData)
84+
})

0 commit comments

Comments
 (0)