|
| 1 | +const presence = new Presence({ |
| 2 | + clientId: '1341778656762134538', |
| 3 | +}) |
| 4 | + |
| 5 | +enum ActivityAssets { |
| 6 | + Logo = 'https://litomore.me/images/jsr-512.png', |
| 7 | +} |
| 8 | + |
| 9 | +presence.on('UpdateData', async () => { |
| 10 | + const presenceData: PresenceData = { |
| 11 | + largeImageKey: ActivityAssets.Logo, |
| 12 | + } |
| 13 | + |
| 14 | + presenceData.details = 'Exploring JSR' |
| 15 | + |
| 16 | + if (document.location.pathname === '/') { |
| 17 | + presenceData.details = 'Viewing the homepage' |
| 18 | + } |
| 19 | + |
| 20 | + const args = document.location.pathname.split('/') |
| 21 | + |
| 22 | + if (args[1] === 'docs') { |
| 23 | + presenceData.details = 'Viewing JSR documentation' |
| 24 | + presenceData.state = document.title |
| 25 | + } |
| 26 | + else if (args[1]?.startsWith('@')) { |
| 27 | + if (args[2] === undefined) { |
| 28 | + presenceData.details = 'Viewing scope' |
| 29 | + presenceData.state = args[1] |
| 30 | + } |
| 31 | + else if (args[2] === '~' && args[3]) { |
| 32 | + presenceData.details = `Viewing scope ${args[3]}` |
| 33 | + presenceData.state = args[1] |
| 34 | + } |
| 35 | + else if (/[-a-z](?:@\d+\.\d+\.\d.*)*/.test(args[2])) { |
| 36 | + const packageName = [args[1], args[2]].join('/') |
| 37 | + presenceData.details = `Viewing package` |
| 38 | + presenceData.state = packageName |
| 39 | + |
| 40 | + if (args[3] === 'doc') { |
| 41 | + presenceData.details = `Viewing package documentation` |
| 42 | + |
| 43 | + if (args[4] === '~' && args[5]) { |
| 44 | + presenceData.details = `Viewing package documentation` |
| 45 | + presenceData.state = `${packageName}: ${args[5]}` |
| 46 | + } |
| 47 | + } |
| 48 | + else if (args[3] === 'versions') { |
| 49 | + presenceData.details = `Viewing package versions` |
| 50 | + } |
| 51 | + else if (args[3] === 'dependencies') { |
| 52 | + presenceData.details = `Viewing package dependencies` |
| 53 | + } |
| 54 | + else if (args[3] === 'dependents') { |
| 55 | + presenceData.details = `Viewing package dependents` |
| 56 | + } |
| 57 | + else if (args[3] === 'score') { |
| 58 | + presenceData.details = `Viewing package score` |
| 59 | + |
| 60 | + const score = document.querySelector('[style^="background-image: conic-gradient"]')?.textContent |
| 61 | + if (score) { |
| 62 | + presenceData.state = `${packageName} (${score})` |
| 63 | + } |
| 64 | + } |
| 65 | + else if (args[3] && /\d+\.\d+\.\d.*/.test(args[3])) { |
| 66 | + presenceData.details = `Viewing package files` |
| 67 | + |
| 68 | + if (args[4]) { |
| 69 | + const [,,,,...fileLocation] = args |
| 70 | + const filePath = fileLocation.join('/') |
| 71 | + presenceData.details = `Viewing package file` |
| 72 | + presenceData.state = filePath |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + presence.setActivity(presenceData) |
| 79 | +}) |
0 commit comments