123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- const presence = new Presence({
- clientId: "629473655218241557",
- }),
- strings = presence.getStrings({
- play: "general.playing",
- pause: "general.paused",
- });
- function getTime(timegone: string[], timetotal: string[]): number[] {
- return [
- parseInt(timegone[0]) + parseInt(timegone[1]) * 60,
- parseInt(timetotal[0]) + parseInt(timetotal[1]) * 60,
- ];
- }
- function getTimeLeft(Time: string[]): number[] {
- const parsedAudioDuration = getTime(
- Time[0].split(":").reverse(),
- Time[1].split(":").reverse()
- );
- return [parsedAudioDuration[0], parsedAudioDuration[1]];
- }
- presence.on("UpdateData", async () => {
- const presenceData: PresenceData = {
- largeImageKey:
- "https://cdn.rcd.gg/PreMiD/websites/M/Musescore/assets/logo.png",
- };
- // ALL ON THE .ORG website
- if (document.location.pathname.endsWith("/forum")) {
- presenceData.details = "Looking at";
- presenceData.state = "the forums.";
- }
- if (document.location.pathname.endsWith("/download")) {
- presenceData.details = "Looking how to";
- presenceData.state = "download Musescore.";
- }
- if (document.location.pathname.includes("/handbook")) {
- presenceData.details = "Looking at";
- presenceData.state = "the handbook.";
- }
- if (document.location.pathname.endsWith("/plugins")) {
- presenceData.details = "Looking at";
- presenceData.state = "plugins.";
- }
- if (document.location.pathname.endsWith("/services")) {
- presenceData.details = "Looking at";
- presenceData.state = "services.";
- }
- if (
- document.location.pathname.includes("/tutorials") ||
- document.location.pathname.includes("/howto")
- ) {
- presenceData.details = "Looking at";
- presenceData.state = "tutorials.";
- }
- if (document.location.pathname.endsWith("/faq")) {
- presenceData.details = "Looking at";
- presenceData.state = "the FAQ.";
- }
- if (document.location.pathname.endsWith("/tracker")) {
- presenceData.details = "Looking at";
- presenceData.state = "recent content.";
- }
- // Main stuff
- if (document.location.pathname.includes("/dashboard")) {
- presenceData.details = "Looking at";
- presenceData.state = "their dashboard.";
- }
- if (document.location.pathname.startsWith("/piano-tutorial")) {
- presenceData.details = "Looking at";
- presenceData.state = "piano tutorials.";
- }
- if (document.location.pathname.startsWith("/community")) {
- presenceData.details = "Looking at";
- presenceData.state = "communities.";
- }
- if (document.location.pathname.includes("/sheetmusic")) {
- presenceData.details = "Looking at";
- presenceData.state = "sheetmusic.";
- }
- if (document.location.pathname.startsWith("/upload")) {
- presenceData.details = "Uploading";
- presenceData.state = "their music.";
- }
- if (document.location.pathname.startsWith("/hub")) {
- presenceData.details = "Looking at";
- presenceData.state = `${
- document.location.pathname.split("/")[2]
- } sheetmusic.`;
- }
- if (document.location.pathname.endsWith("/my-scores")) {
- presenceData.details = "Looking at";
- presenceData.state = "their sheetmusic.";
- }
- if (document.location.pathname.startsWith("/upgrade")) {
- presenceData.details = "Considering";
- presenceData.state = "upgrading to pro.";
- }
- if (document.location.pathname.startsWith("/checkout")) {
- presenceData.details = "Checking something";
- presenceData.state = "out.";
- }
- if (document.location.pathname.endsWith("/group/create")) {
- presenceData.details = "Creating a";
- presenceData.state = "new group.";
- }
- if (document.location.pathname.endsWith("/community-guidelines")) {
- presenceData.details = "Browsing the";
- presenceData.state = "community guidelines.";
- }
- if (
- document.location.pathname.endsWith("/press") ||
- document.location.pathname.endsWith("/news")
- ) {
- presenceData.details = "Browsing the";
- presenceData.state = "press.";
- }
- if (document.location.pathname.endsWith("/jobs")) {
- presenceData.details = "Looking at";
- presenceData.state = "job opportunities.";
- }
- if (document.location.pathname.endsWith("/about")) {
- presenceData.details = "Looking at";
- presenceData.state = "the about section.";
- }
- if (document.location.pathname.startsWith("/hc")) {
- presenceData.details = "Looking at";
- presenceData.state = "the help center.";
- }
- if (document.location.pathname.startsWith("/contact")) {
- presenceData.details = "Contacting";
- presenceData.state = "Musescore.";
- }
- // This is here since some profiles dont have user.
- if (
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- )
- ) {
- presenceData.details = "Browing";
- presenceData.state = `${
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- ).textContent
- }'s profile`;
- }
- // MUSIC PLAYING / PAUSING
- if (
- document.querySelector(
- "#jmuse-container > div.viewer > div.viewerWrapper > div"
- )
- ) {
- if (
- `${document
- .querySelector(
- "#jmuse-container > div:nth-child(1) > div > div > div > div._1DDmo.undefined > div:nth-child(1) > div > div > div.oY3Aa > button"
- )
- .getAttribute("state")}` === "default"
- ) {
- presenceData.smallImageKey = Assets.Pause;
- presenceData.details = "Looking at";
- presenceData.state = document.querySelector(
- "body > div.page.page-score > div.container > div.row > main > article > div > div.score-right > h1"
- ).textContent;
- presenceData.smallImageText = (await strings).pause;
- } else if (
- `${document
- .querySelector(
- "#jmuse-container > div:nth-child(1) > div > div > div > div._1DDmo.undefined > div:nth-child(1) > div > div > div.oY3Aa > button"
- )
- .getAttribute("state")}` === "primary"
- ) {
- const time = getTimeLeft([
- document
- .querySelector(
- "#jmuse-container > div:nth-child(1) > div > div > div > div._1DDmo.undefined > div:nth-child(1) > div > div > div._3vWaq > span"
- )
- .textContent.split("/")[0],
- document
- .querySelector(
- "#jmuse-container > div:nth-child(1) > div > div > div > div._1DDmo.undefined > div:nth-child(1) > div > div > div._3vWaq > span"
- )
- .textContent.split("/")[1],
- ]);
- [presenceData.startTimestamp, presenceData.endTimestamp] =
- presence.getTimestamps(time[0], time[1]);
- presenceData.smallImageKey = Assets.Play;
- presenceData.details = "Listening to";
- presenceData.state = document.querySelector(
- "body > div.page.page-score > div.container > div.row > main > article > div > div.score-right > h1"
- ).textContent;
- presenceData.smallImageText = (await strings).play;
- }
- }
- if (document.location.pathname.includes("/user")) {
- if (document.location.pathname.includes("/edit")) {
- presenceData.details = "Editing";
- presenceData.state = "their account.";
- }
- if (document.location.pathname.includes("settings/profile")) {
- presenceData.details = "Editing";
- presenceData.state = "their profile.";
- }
- if (document.location.pathname.includes("subscription")) {
- presenceData.details = "Viewing a";
- presenceData.state = "subscription.";
- }
- if (document.location.pathname.includes("billing")) {
- presenceData.details = "Viewing their";
- presenceData.state = "billing history.";
- }
- if (document.location.pathname.includes("gifts")) {
- presenceData.details = "Viewing their";
- presenceData.state = "gifts.";
- }
- if (document.location.pathname.includes("notifications")) {
- presenceData.details = "Viewing their";
- presenceData.state = "notifications.";
- }
- if (document.location.pathname.includes("/message")) {
- presenceData.details = "Looking at";
- presenceData.state = "messages.";
- }
- if (document.location.pathname.includes("/followers")) {
- presenceData.details = "Looking at";
- presenceData.state = `${
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- ).textContent
- }'s followers.`;
- }
- if (document.location.pathname.includes("/following")) {
- presenceData.details = "Looking who";
- presenceData.state = `${
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- ).textContent
- } is following.`;
- }
- if (document.location.pathname.includes("/invite")) {
- presenceData.details = "Inviting";
- presenceData.state = "some friends.";
- }
- if (
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header.collapsed > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- )
- ) {
- presenceData.details = "Browing";
- presenceData.state = `${
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header.collapsed > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- ).textContent
- }'s profile`;
- }
- } else if (
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- )
- ) {
- if (document.location.pathname.includes("/sheetmusic")) {
- presenceData.details = "Looking at";
- presenceData.state = `${
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- ).textContent
- }'s sheetmusic.`;
- }
- if (document.location.pathname.includes("/favorites")) {
- presenceData.details = "Looking at";
- presenceData.state = `${
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- ).textContent
- }'s favorites.`;
- }
- if (document.location.pathname.includes("/sets")) {
- presenceData.details = "Looking at";
- presenceData.state = `${
- document.querySelector(
- "body > div.page.js-user-profile-page > div.content-header > div.banner-header.group-header > div > div.info-wrapper.group-info-wrapper.user-info-wrapper > div > h1 > a"
- ).textContent
- }'s sets.`;
- }
- }
- presence.setActivity(presenceData);
- });
|