Skip to content

Instantly share code, notes, and snippets.

@Kreozot
Last active January 20, 2023 08:41
Show Gist options
  • Save Kreozot/256bbe31ff4ba8cc50afbbd7cdf9d2f2 to your computer and use it in GitHub Desktop.
Save Kreozot/256bbe31ff4ba8cc50afbbd7cdf9d2f2 to your computer and use it in GitHub Desktop.
const TRACKS_SELECTOR = 'div.d-track__overflowable-column > div.d-track__overflowable-wrapper.deco-typo-secondary.block-layout';
const TRACK_NAME_SELECTOR = '.d-track__title';
const TRACK_VERSION_SELECTOR = '.d-track__version';
const TRACK_ARTISTS_SELECTOR = '.d-track__artists > a';
const trackElements = document.querySelectorAll(TRACKS_SELECTOR);
const tracks = [];
trackElements.forEach((trackElement) => {
const name = trackElement.querySelector(TRACK_NAME_SELECTOR).innerHTML.trim();
const version = trackElement.querySelector(TRACK_VERSION_SELECTOR)?.innerHTML.trim();
const artistElements = trackElement.querySelectorAll(TRACK_ARTISTS_SELECTOR);
const artists = [];
artistElements.forEach((artistElement) => artists.push(artistElement.innerHTML.trim()));
tracks.push({
name,
version,
artists,
});
});
const result = tracks.map(({name, version, artists}) => `${artists.join(', ')}: ${name}${version ? ` (${version})` : ''}`);
const resultArrayString = JSON.stringify(result, null, 2);
navigator.clipboard.writeText(resultArrayString);
console.log(resultArrayString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment