forked from PreMiD/Presences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MetaBrainz): add presence (PreMiD#6771)
* feat(MetaBrainz): prepare metadata * feat(MetaBrainz): add root and blog subdomain presences * feat(MetaBrainz): add presence for community forums * refactor(MetaBrainz): run eslint * fix(MetaBrainz): use correct image for profile * chore(MetaBrainz): sort metadata * style(MetaBrainz): run prettier
- Loading branch information
Showing
3 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.7", | ||
"author": { | ||
"name": "theusaf", | ||
"id": "193714715631812608" | ||
}, | ||
"service": "MetaBrainz", | ||
"description": { | ||
"en": "The MetaBrainz Foundation is a non-profit that believes in free, open access to data. It has been set up to build community maintained databases and make them available in the public domain or under Creative Commons licenses." | ||
}, | ||
"url": [ | ||
"metabrainz.org", | ||
"blog.metabrainz.org", | ||
"community.metabrainz.org" | ||
], | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/kQsG9xv.png", | ||
"thumbnail": "https://i.imgur.com/si5Pxzc.png", | ||
"color": "#5aa854", | ||
"category": "other", | ||
"tags": [ | ||
"public", | ||
"community", | ||
"data", | ||
"database" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
const presence = new Presence({ | ||
clientId: "1017489991930232902", | ||
}), | ||
browsingTimestamp = Math.floor(Date.now() / 1000); | ||
|
||
presence.on("UpdateData", () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: "https://i.imgur.com/kQsG9xv.png", | ||
startTimestamp: browsingTimestamp, | ||
}, | ||
{ hostname, pathname, search } = window.location; | ||
switch (hostname) { | ||
case "metabrainz.org": { | ||
presenceData.details = "Browsing..."; | ||
switch (pathname) { | ||
case "/": { | ||
presenceData.state = "Home page"; | ||
break; | ||
} | ||
case "/profile": { | ||
presenceData.details = "Viewing MetaBrainz profile"; | ||
presenceData.state = new URLSearchParams(search).get( | ||
"musicbrainz_id" | ||
); | ||
break; | ||
} | ||
default: { | ||
presenceData.state = document.title.split( | ||
" - MetaBrainz Foundation" | ||
)[0]; | ||
} | ||
} | ||
break; | ||
} | ||
case "blog.metabrainz.org": { | ||
presenceData.details = "Reading blog"; | ||
if (pathname === "/") presenceData.state = "Home page"; | ||
else if (pathname.startsWith("/author/")) { | ||
presenceData.state = `Viewing articles by ${ | ||
pathname.match(/^\/author\/(.*?)\//)[1] | ||
}`; | ||
} else if (pathname.startsWith("/tag/")) { | ||
presenceData.state = `Viewing articles tagged '${ | ||
document.querySelector<HTMLSpanElement>(".page-title > span") | ||
?.textContent || pathname.match(/^\/tag\/(.*?)\//)[1] | ||
}'`; | ||
} else if (pathname.startsWith("/category/")) { | ||
presenceData.state = `Viewing category '${ | ||
document.querySelector<HTMLSpanElement>(".page-title > span") | ||
?.textContent || pathname.match(/^\/category\/(.*?)\//)[1] | ||
}'`; | ||
} else if (/^\/\d+\/(\d+\/)?$/.test(pathname)) { | ||
presenceData.state = `Viewing articles created in ${ | ||
document.querySelector<HTMLSpanElement>(".page-title > span") | ||
.textContent | ||
}`; | ||
} else { | ||
presenceData.state = | ||
document.querySelector<HTMLHeadingElement>( | ||
".entry-title" | ||
).textContent; | ||
} | ||
break; | ||
} | ||
case "community.metabrainz.org": { | ||
presenceData.details = "Browsing forum"; | ||
presenceData.largeImageKey = "https://i.imgur.com/AtrEqxF.png"; | ||
if (pathname === "/") presenceData.state = "Home page"; | ||
else if (pathname.startsWith("/c/") || /^\/tags\/c\/.+/.test(pathname)) { | ||
presenceData.state = `Viewing category '${ | ||
document.querySelector<HTMLSpanElement>(".category-name").textContent | ||
}'`; | ||
} else if (pathname.startsWith("/t/")) { | ||
presenceData.state = | ||
document.querySelector<HTMLAnchorElement>(".fancy-title").textContent; | ||
} else if (/^\/g\/.+/.test(pathname)) { | ||
presenceData.state = `Viewing group '${ | ||
document.querySelector<HTMLSpanElement>(".group-info-name") | ||
.textContent | ||
}'`; | ||
} else if (/^\/categories\/?/.test(pathname)) | ||
presenceData.state = "Viewing categories"; | ||
else if (pathname === "/login-preferences") | ||
presenceData.state = "Logging in"; | ||
else if (pathname.startsWith("/u/")) { | ||
presenceData.state = `Viewing profile of ${ | ||
document.querySelector<HTMLHeadingElement>(".username").textContent | ||
}`; | ||
presenceData.smallImageKey = document.querySelector<HTMLImageElement>( | ||
".user-profile-avatar > img" | ||
).src; | ||
presenceData.smallImageText = | ||
document.querySelector<HTMLHeadingElement>(".full-name").textContent; | ||
} else { | ||
presenceData.state = document.title.split( | ||
" - MetaBrainz Community Discourse" | ||
)[0]; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
if (presenceData.details) presence.setActivity(presenceData); | ||
else presence.setActivity(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist/" | ||
} | ||
} |