Skip to content

Commit

Permalink
feat(JSR): add JSR presence
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Feb 19, 2025
1 parent 8466b74 commit 7805c47
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
22 changes: 22 additions & 0 deletions websites/J/JSR/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://schemas.premid.app/metadata/1.13",
"apiVersion": 1,
"author": {
"id": "357461892526243840",
"name": "litomore"
},
"service": "JSR",
"description": {
"en": "The open-source package registry for modern JavaScript and TypeScript."
},
"url": "jsr.io",
"version": "1.0.0",
"logo": "https://avatars.githubusercontent.com/u/158506965?s=500&v=4&.png",
"thumbnail": "https://avatars.githubusercontent.com/u/158506965?s=500&v=4&.png",
"color": "#000000",
"category": "other",
"tags": [
"programming",
"registry"
]
}
79 changes: 79 additions & 0 deletions websites/J/JSR/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const presence = new Presence({
clientId: '1341778656762134538',
})

enum ActivityAssets { // Other default assets can be found at index.d.ts
Logo = 'https://avatars.githubusercontent.com/u/158506965?s=500&v=4',
}

presence.on('UpdateData', async () => {
const presenceData: PresenceData = {
largeImageKey: ActivityAssets.Logo,
}

presenceData.details = 'Exploring JSR'

if (document.location.pathname === '/') {
presenceData.details = 'Viewing the homepage'
}

const args = document.location.pathname.split('/')

if (args[1] === 'docs') {
presenceData.details = 'Viewing JSR documentation'
presenceData.state = document.title
}
else if (args[1]?.startsWith('@')) {
if (args[2] === undefined) {
presenceData.details = 'Viewing scope'
presenceData.state = args[1]
}
else if (args[2] === '~' && args[3]) {
presenceData.details = `Viewing scope ${args[3]}`
presenceData.state = args[1]
}
else if (/[-a-z](?:@\d+\.\d+\.\d.*)*/.test(args[2])) {
const packageName = [args[1], args[2]].join('/')
presenceData.details = `Viewing package`
presenceData.state = packageName

if (args[3] === 'doc') {
presenceData.details = `Viewing package documentation`

if (args[4] === '~' && args[5]) {
presenceData.details = `Viewing package documentation`
presenceData.state = `${packageName}: ${args[5]}`
}
}
else if (args[3] === 'versions') {
presenceData.details = `Viewing package versions`
}
else if (args[3] === 'dependencies') {
presenceData.details = `Viewing package dependencies`
}
else if (args[3] === 'dependents') {
presenceData.details = `Viewing package dependents`
}
else if (args[3] === 'score') {
presenceData.details = `Viewing package score`

const score = document.querySelector('[style^="background-image: conic-gradient"]')?.textContent
if (score) {
presenceData.state = `${packageName} (${score})`
}
}
else if (args[3] && /\d+\.\d+\.\d.*/.test(args[3])) {
presenceData.details = `Viewing package files`

if (args[4]) {
const [,,,,...fileLocation] = args
const filePath = fileLocation.join('/')
presenceData.details = `Viewing package file`
presenceData.state = filePath
}
}
}
}

presence.setActivity(presenceData)
})

0 comments on commit 7805c47

Please sign in to comment.