From 7a30b125ec9bb5940cbe20cd83ac9da43b76bf0e Mon Sep 17 00:00:00 2001 From: Marie <8841466+Mar0xy@users.noreply.github.com> Date: Wed, 21 Apr 2021 03:31:28 +0200 Subject: [PATCH] Add switch case for Video/Song --- src/preload.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/preload.js b/src/preload.js index 2e1553c..b85e49b 100644 --- a/src/preload.js +++ b/src/preload.js @@ -15,6 +15,7 @@ let currentPlayStatus = statuses.paused; let barvalue; let updatecurrent = false; let oldcurrent; +let currentURL = undefined; const elements = { play: '*[data-test="play"]', @@ -22,7 +23,7 @@ const elements = { next: '*[data-test="next"]', previous: 'button[data-test="previous"]', title: '*[data-test^="footer-track-title"]', - artists: '*[data-test^="grid-item-detail-text-title-artist"]', + artists: '*[class^="elemental__text elemental__text css-oxcos"]', home: '*[data-test="menu--home"]', back: '[class^="backwardButton"]', forward: '[class^="forwardButton"]', @@ -249,7 +250,7 @@ function updateMediaInfo(options, notify) { */ setInterval(function () { const title = elements.getText("title"); - const url = elements.get("url").href.replace(/[^0-9]/g, ""); + //const id = elements.get("url").href.replace(/[^0-9]/g, ""); const artists = elements.getText("artists"); const current = elements.getText("current"); const duration = elements.getText("duration"); @@ -260,7 +261,7 @@ setInterval(function () { title, message: artists, status: currentStatus, - url: `https://tidal.com/browse/track/${url}`, + url: currentURL, current: current, duration: duration, }; @@ -283,6 +284,17 @@ setInterval(function () { updatecurrent = true; } + // Video/Song check if it's a video return URL as undefined due to it not having an id. + switch(elements.get("url")) { + case null: + currentURL = undefined; + break; + default: + const id = elements.get("url").href.replace(/[^0-9]/g, ""); + currentURL = `https://tidal.com/browse/track/${id}`; + break; + } + if(updatecurrent) { if(options.current == oldcurrent && currentStatus != "paused") return; oldcurrent = options.current;