From 7655f794b373022036638fa87ae48928d8740d90 Mon Sep 17 00:00:00 2001 From: Dark_Ville <42322979+DarkVillager@users.noreply.github.com> Date: Sun, 21 Jul 2024 21:53:35 +0200 Subject: [PATCH] feat(iBroadCast): add typing, cover with setting & improve code (#8585) --- websites/I/iBroadcast/metadata.json | 10 ++++- websites/I/iBroadcast/presence.ts | 64 +++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/websites/I/iBroadcast/metadata.json b/websites/I/iBroadcast/metadata.json index e56213e88546..41f32e2e9c91 100644 --- a/websites/I/iBroadcast/metadata.json +++ b/websites/I/iBroadcast/metadata.json @@ -10,7 +10,7 @@ }, "url": "www.ibroadcast.com", "regExp": "(beta|media|edit).ibroadcast.com", - "version": "1.1.16", + "version": "1.2.0", "logo": "https://cdn.rcd.gg/PreMiD/websites/I/iBroadcast/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/I/iBroadcast/assets/thumbnail.jpg", "color": "#53abee", @@ -18,5 +18,13 @@ "tags": [ "music", "personal-library" + ], + "settings": [ + { + "id": "cover", + "title": "Show Cover", + "icon": "fad fa-images", + "value": true + } ] } \ No newline at end of file diff --git a/websites/I/iBroadcast/presence.ts b/websites/I/iBroadcast/presence.ts index e104aa787148..ac348c78f47a 100644 --- a/websites/I/iBroadcast/presence.ts +++ b/websites/I/iBroadcast/presence.ts @@ -3,32 +3,34 @@ const presence = new Presence({ }), browsingTimestamp = Math.floor(Date.now() / 1000); +const enum Assets { + Logo = "https://cdn.rcd.gg/PreMiD/websites/I/iBroadcast/assets/logo.png", +} + presence.on("UpdateData", async () => { const presenceData: PresenceData = { largeImageKey: - "https://cdn.rcd.gg/PreMiD/websites/I/iBroadcast/assets/logo.png", + document.querySelector( + ".mgr-container-artwork-single,.mgr-player-artwork-image" + )?.src ?? Assets.Logo, startTimestamp: browsingTimestamp, }, + cover = await presence.getSetting("cover"), { hostname } = document.location; if (hostname.startsWith("edit")) presenceData.details = "Editing Library"; else if (hostname.startsWith("beta") || hostname.startsWith("media")) { - const playlist: HTMLDivElement = document.querySelector( - ".mgr-list-tracks-title" - ), - popup: HTMLDivElement = document.querySelector( - "body > div.mgr-modal.mgr-modal-opaque > div > div.mgr-title" + const playlist = document.querySelector(".mgr-list-tracks-title"), + popup = document.querySelector( + "div.mgr-modal.mgr-modal-opaque > div > div.mgr-title" ); if (document.querySelector(".icon-player-pause")) { - const title: HTMLDivElement = document.querySelector(".mgr-player-title"), - artist: HTMLDivElement = document.querySelector(".mgr-player-artist"), - currentTime: HTMLDivElement = document.querySelector( - ".mgr-player-current-time" - ), - duration: HTMLDivElement = document.querySelector( - ".mgr-player-duration" - ); + presenceData.type = ActivityType.Listening; + const title = document.querySelector(".mgr-player-title"), + artist = document.querySelector(".mgr-player-artist"), + currentTime = document.querySelector(".mgr-player-current-time"), + duration = document.querySelector(".mgr-player-duration"); if (title && artist) { presenceData.details = `${title.textContent} by ${artist.textContent}`; @@ -42,12 +44,38 @@ presence.on("UpdateData", async () => { ); } } else if (playlist) { - presenceData.details = "Looking at playlist"; - presenceData.state = playlist.textContent; - } else if (popup) presenceData.details = `Viewing ${popup.textContent}`; - else presenceData.details = "At homepage"; + presenceData.details = "Looking at a playlist"; + presenceData.state = playlist?.textContent ?? ""; + } else if (popup?.textContent) + presenceData.details = `Viewing ${popup.textContent}`; + else { + switch ( + document.querySelector(".mgr-menu-item.mgr-menu-item-selected") + ?.textContent + ) { + case "Album Artists": { + const albumSelected = document.querySelector( + ".mgr-list-tracks-title" + )?.textContent; + + if (albumSelected) { + presenceData.details = "Viewing album artists"; + presenceData.state = albumSelected; + } else { + presenceData.details = "Viewing all album artists"; + presenceData.largeImageKey = Assets.Logo; + } + break; + } + default: { + presenceData.details = "Browsing..."; + } + } + } } + if (!cover && presenceData.largeImageKey !== Assets.Logo) + presenceData.largeImageKey = Assets.Logo; if (presenceData.details) presence.setActivity(presenceData); else presence.setActivity(); });