Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Last.fm duplicate scrobble deleter
var elements = Array.from(document.querySelectorAll('.js-link-block'))
elements.map(function (element) {
var nameElement = element.querySelector('.chartlist-name')
return nameElement && nameElement.textContent.replace(/\s+/g, ' ').trim()
}).forEach(function (name, i, names) {
if (name !== names[i + 1]) return
var deleteButton = elements[i].querySelector('[data-ajax-form-sets-state="deleted"]')
if (deleteButton) deleteButton.click()
location.reload()
})

Last.fm duplicate scrobble deleter

This script serves to delete duplicate scrobbles (i.e. the same song scrobbled multiple times in a row) from your Last.fm library. To use it, paste the script into your browser's console (or the address bar, but prefix the script with javascript:) while logged in and in the own library.

Why would I need this?

If you're like me, you might have accidentally installed multiple scrobbler extensions at the same time - wondering why multiple scrobbles appear for every song played at a time - and you want to clear them after finding the issue.

How-to

  1. Copy the one-line script
  2. Open your Last.fm account's library while being logged in (https://www.last.fm/user/your_username_here/library).
  3. Type javascript: into the address bar and paste the script directly after it.3. Press enter. This will remove all duplicates on the current page.
  4. Let the site reload (invoked by the script).
  5. Repeat pasting the script and pressing enter if more duplicates appear at the bottom.
  6. If needed, go to the next page of your library repeat the steps as of step 3.

Script

var elements=Array.from(document.querySelectorAll('.js-link-block'));elements.map(function(a){var b=a.querySelector('.chartlist-name');return b&&b.textContent.replace(/\s+/g,' ').trim()}).forEach(function(a,b,c){if(a===c[b+1]){var d=elements[b].querySelector('[data-ajax-form-sets-state="deleted"]');d&&d.click(),location.reload()}});

Why do I need to repeat executing the script?

The script will only remove what's visible on the current library page. After entries were deleted, more duplicates may appear at the bottom. This might happen multiple times. Once one page is finally duplicate-free, the process can be repeated for next pages.

Why isn't the repetition done automatically?

Well, reloading the page causes scripts to stop (although using a Web Worker or Userscript would probably have worked). Thus, the script needs to be re-executed by the user manually.

[script]: var elements=Array.from(document.querySelectorAll('.js-link-block'));elements.map(function(a){var b=a.querySelector('.chartlist-name');return b&&b.textContent.replace(/\s+/g,' ').trim()}).forEach(function(a,b,c){if(a===c[b+1]){var d=elements[b].querySelector('.dropdown-menu-clickable-item');d&&d.click(),location.reload()}});

var elements=Array.from(document.querySelectorAll('.js-link-block'));elements.map(function(a){var b=a.querySelector('.chartlist-name');return b&&b.textContent.replace(/\s+/g,' ').trim()}).forEach(function(a,b,c){if(a===c[b+1]){var d=elements[b].querySelector('[data-ajax-form-sets-state="deleted"]');d&&d.click(),location.reload()}});

d-ly commented Aug 14, 2017

Thank you for this! Question: For whatever reason, my duplicates sometimes scrobble in an alternating pattern, eg. a b a b c d c d. Is there a way to make a variant that takes care of these duplicates as well? Is it just a matter of changing the if (name !== names[i + 1]) return to if (name !== names[i + 2]) return?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment