|
| 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