Skip to content

Instantly share code, notes, and snippets.

@delucis
Last active July 27, 2020 10:49
Show Gist options
  • Save delucis/28dd7c85acd40fa1dbb9459b39072905 to your computer and use it in GitHub Desktop.
Save delucis/28dd7c85acd40fa1dbb9459b39072905 to your computer and use it in GitHub Desktop.
Programmatically delete scrobbles from a Last.fm library page
/**
* Delete all (or some of) the scrobbles on a Last.fm library page
* (e.g. https://www.last.fm/user/USERNAME/library)
*
* @param {Number} [count=0] Number of scrobbles on page to delete
* @param {Number} [start=0] Index to start deleting from
*
* @example
* // delete first 20 scrobbles on page
* deleteScrobbles(20)
*
* // delete fifth track on page
* deleteScrobbles(1, 4)
*/
function deleteScrobbles (count = 0, start = 0) {
// collect delete buttons from document
const els = document.getElementsByClassName('more-item--delete')
// make sure we’re not deleting more scrobbles than are on the page
start = Math.min(start, els.length - 1)
const end = start + Math.min(count, els.length - start)
// click on each delete button
for (let i = start; i < end; i++) {
els[i].click()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment