Skip to content

Commit

Permalink
fix: fixing how we get the artistName
Browse files Browse the repository at this point in the history
  • Loading branch information
guivictorr committed Feb 2, 2024
1 parent e154752 commit be1f83b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/chorus-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`;
Expand Down
13 changes: 10 additions & 3 deletions src/song-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit be1f83b

Please sign in to comment.