Skip to content

Commit

Permalink
✨ Added YouTube Music Buttons (PreMiD#4173)
Browse files Browse the repository at this point in the history
* ✨ Added YouTube Music Buttons

* 🤷🏽‍♂️

Co-authored-by: Rhys Rakoff <rhysrakoff@rhys.home>
  • Loading branch information
EncryptedDev and Rhys Rakoff authored Aug 2, 2021
1 parent b9a0572 commit a04aa02
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
14 changes: 11 additions & 3 deletions websites/Y/YouTube Music/dist/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@
"ga_IE": "Seirbhís nua ceoil le halbaim oifigiúla, singles, físeáin, remixes, léirithe beo agus go leor eile do Android, iOS agus deasc. Tá sé ar fad anseo."
},
"url": "music.youtube.com",
"version": "2.5.11",
"version": "2.5.12",
"logo": "https://i.imgur.com/cIZnPDy.png",
"thumbnail": "https://i.imgur.com/iQ8MA50.png",
"color": "#E40813",
"tags": [
"audio",
"music"
],
"category": "music"
}
"category": "music",
"settings": [
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true
}
]
}
40 changes: 22 additions & 18 deletions websites/Y/YouTube Music/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ function getAuthorString(): string {
document.querySelector(
"span yt-formatted-string.ytmusic-player-bar a"
) as HTMLAnchorElement
).innerText
).innerText
: (
document.querySelector(
"span yt-formatted-string.ytmusic-player-bar span:nth-child(1)"
) as HTMLAnchorElement
).innerText;
).innerText;
}

return authorString;
Expand All @@ -71,7 +71,8 @@ presence.on("UpdateData", async () => {
video = document.querySelector(".video-stream") as HTMLVideoElement,
repeatMode = document
.querySelector('ytmusic-player-bar[slot="player-bar"]')
.getAttribute("repeat-Mode_");
.getAttribute("repeat-Mode_"),
buttons = await presence.getSetting("buttons");

if (title !== "" && !isNaN(video.duration)) {
const [, endTimestamp] = presence.getTimestamps(
Expand All @@ -88,26 +89,29 @@ presence.on("UpdateData", async () => {
smallImageKey: video.paused
? "pause"
: repeatMode === "ONE"
? "repeat-one"
: repeatMode === "ALL"
? "repeat"
: "play",
? "repeat-one"
: repeatMode === "ALL"
? "repeat"
: "play",
smallImageText: video.paused
? (await strings).pause
: repeatMode === "ONE"
? "On loop"
: repeatMode === "ALL"
? "Playlist on loop"
: (await strings).play,
endTimestamp,
buttons: [
{
label: "Listen Along",
url: `https://music.youtube.com/watch?v=${watchID}`
}
]
? "On loop"
: repeatMode === "ALL"
? "Playlist on loop"
: (await strings).play,
endTimestamp
};

if (buttons) {
presenceData.buttons = [
{
label: "Listen Along",
url: `https://music.youtube.com/watch?v=${watchID}`
}
];
}

if (video.paused) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
Expand Down

0 comments on commit a04aa02

Please sign in to comment.