Skip to content

Instantly share code, notes, and snippets.

@ChristianGaertner
Created November 25, 2017 12:02
Show Gist options
  • Save ChristianGaertner/8ffc2a5194268c43cf1c90b829eb744d to your computer and use it in GitHub Desktop.
Save ChristianGaertner/8ffc2a5194268c43cf1c90b829eb744d to your computer and use it in GitHub Desktop.
last.fm currently playing track
const username = 'lastfm_username';
fetch(`https://cors-anywhere.herokuapp.com/https://www.last.fm/user/${username}`).then(r => r.text()).then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
const name = doc.querySelector('.now-scrobbling .chartlist-name > span > a').innerHTML;
const artist = doc.querySelector('.now-scrobbling .chartlist-name .chartlist-artists a').innerHTML;
return [name, artist];
}).then(console.log.bind(console));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment