Skip to content

Instantly share code, notes, and snippets.

@toby3d
Created February 12, 2020 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toby3d/531f7790eee15c17b307479ca0f4aea4 to your computer and use it in GitHub Desktop.
Save toby3d/531f7790eee15c17b307479ca0f4aea4 to your computer and use it in GitHub Desktop.
Removes duplicates scrobblings in your last.fm library

Remove last.fm duplicates

  1. Select all code below and move this script on your bookmarks tab, rename it as you want:
javascript:(function(){var found = 0; var num = 5; var sections = Array.from(document.getElementsByTagName('tbody'));  function replaceQueryParam(param, newval, search) { var regex = new RegExp('([?;&])' + param + '[^&;]*[;&]?'); var query = search.replace(regex, '$1').replace(/&$/, ''); return (query.length > 2 ? query + '&' : '?') + (newval ? param + '=' + newval : ''); };   function gup( name, url ) { if (!url) url = location.href; name = name.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]'); var regexS = '[\\?&]'+name+'=([^&#]*)';%20var%20regex%20=%20new%20RegExp(%20regexS%20);%20var%20results%20=%20regex.exec(%20url%20);%20return%20results%20==%20null%20?%20null%20:%20results[1];%20};%20%20sections.forEach(function%20(section)%20{%20var%20els%20=%20Array.from(section.rows);%20var%20names%20=%20els.map(function%20(el)%20{%20var%20nmEl%20=%20el.querySelector('.chartlist-name');%20var%20artEl%20=%20el.querySelector('.chartlist-artist');%20return%20nmEl%20&&%20artEl%20&&%20nmEl.textContent.replace(/\s+/g,%20'%20').trim()+':'+artEl.textContent.replace(/\s+/g,%20'%20').trim();%20});%20%20names.forEach(function%20(name,%20i,%20names)%20{%20if%20(!names.slice(i%20+%201,%20i%20+%201%20+%20num).includes(name))%20return;%20var%20delBtn%20=%20els[i].querySelector('[data-ajax-form-sets-state='deleted']');%20if%20(delBtn)%20{%20delBtn.click();%20found++;%20};%20});%20});%20%20if%20(found%20>%200)%20setTimeout(function()%20{%20location.reload();%20},%205000);%20else%20window.location%20=%20window.location.pathname%20+%20replaceQueryParam('page',%20gup('page',%20window.location.href)%20-%201,%20window.location.search);})();
  1. Open your library on https://www.last.fm/user/{username}/library
  2. Go to last/specific page in library
  3. Click on your script bookmark
  4. ?????????
  5. PROFIT!!1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment