diff --git a/src/chorus-button.ts b/src/chorus-button.ts index 122592d..083fba3 100644 --- a/src/chorus-button.ts +++ b/src/chorus-button.ts @@ -7,13 +7,9 @@ function buildChorusIcon() { } function buildChorusUrl(songName: string | null, artistName: string | null) { - if (!songName || !artistName) { - return; - } - const query = new URLSearchParams({ - name: songName, - artist: artistName, + name: songName ?? '', + artist: artistName ?? '', }); return `https://www.enchor.us?${query.toString()}`; diff --git a/src/song-info.ts b/src/song-info.ts index 1a91060..49c81a4 100644 --- a/src/song-info.ts +++ b/src/song-info.ts @@ -13,11 +13,18 @@ export function getSongInfoFrom(offsetParent: Element) { 'a[data-testid="context-item-link"], a[data-testid="internal-track-link"], a[href^="/track"]', ); const artistNameElement = Array.from( - document.querySelectorAll('a[href^="/artist"]'), - ).shift(); + offsetParent.querySelectorAll('a[href^="/artist"]'), + ).pop(); + + const artistNameElementFallback = document.querySelector( + 'span[data-testid="entityTitle"]', + ); + const artistElement = artistNameElement + ? artistNameElement + : artistNameElementFallback; const songName = sanitizeSongName(songNameElement?.textContent); - const artistName = artistNameElement?.textContent ?? null; + const artistName = artistElement?.textContent ?? null; return { songName,