Skip to content
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

feat(JSR): add JSR presence #9301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://litomore.me/images/jsr-512.png",
"thumbnail": "https://litomore.me/images/jsr-thumbnail.webp",
"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 {
Logo = 'https://avatars.githubusercontent.com/u/158506965?s=500',
}

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)
})
Loading