Skip to content

Instantly share code, notes, and snippets.

@phoebejaffe
Created November 11, 2019 16:06
Show Gist options
  • Select an option

  • Save phoebejaffe/949d6c91cfbcda065193b0a39e3638bb to your computer and use it in GitHub Desktop.

Select an option

Save phoebejaffe/949d6c91cfbcda065193b0a39e3638bb to your computer and use it in GitHub Desktop.
// Run this on https://www.musicgenreslist.com/ to select a random genre and search spotify for it
let genres, chooseGenre;
genres = genres || Array.from(document.getElementsByTagName('li'))
.filter(elem => elem.innerHTML === elem.textContent);
chooseGenre = chooseGenre || (() => {
const choice = genres[Math.floor(Math.random() * genres.length)];
const parenIndex = choice.textContent.indexOf(' (');
const text = parenIndex < 0 ? choice.textContent : choice.textContent.slice(0, parenIndex);
const doIt = confirm(text + '?');
if (!doIt) {
chooseGenre();
return;
}
const escapedText = escape((text).trim());
window.open(`https://open.spotify.com/search/${escapedText}/playlists`);
})
chooseGenre();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment