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.
- Copy the following script URL into your clipboard
javascript:var max = 20; var num = 5; var counter = 1; var sections = Array.from(document.getElementsByTagName("tbody")); sections.forEach(function (section) { var elements = Array.from(section.rows); var titles = elements.map(function (element) { var nameElement = element.querySelector('.chartlist-name'); var artistElement = element.querySelector('.chartlist-artist'); return nameElement && artistElement && nameElement.textContent.replace(/\s+/g, ' ').trim()+':'+artistElement.textContent.replace(/\s+/g, ' ').trim(); }); titles.forEach(function (title, i, titles) { if (counter > max) { throw new Error("Max Reached!"); } else {counter++}; if (!titles.slice(i + 1, i + 1 + num).includes(title)) return; var deleteButton = elements[i].querySelector('[data-ajax-form-sets-state="deleted"]'); if (deleteButton) deleteButton.click(); }); })- Right-click your browser's bookmark bar and click "Add page..."
- Give the bookmark a name, like "Remove duplicates"
- Paste the script you copied in step 1 into the bookmark's URL.
- Save the bookmark
- Open your Last.fm account's library while being logged in (https://www.last.fm/user/_/library).
- Opening your bookmark will trigger the script to execute.
- Repeat clicking the bookmark as long as there are no duplicates left.
- Copy the script
var max = 20; var num = 5; var counter = 1; var sections = Array.from(document.getElementsByTagName("tbody")); sections.forEach(function (section) { var elements = Array.from(section.rows); var titles = elements.map(function (element) { var nameElement = element.querySelector('.chartlist-name'); var artistElement = element.querySelector('.chartlist-artist'); return nameElement && artistElement && nameElement.textContent.replace(/\s+/g, ' ').trim()+':'+artistElement.textContent.replace(/\s+/g, ' ').trim(); }); titles.forEach(function (title, i, titles) { if (counter > max) { throw new Error("Max Reached!"); } else {counter++}; if (!titles.slice(i + 1, i + 1 + num).includes(title)) return; var deleteButton = elements[i].querySelector('[data-ajax-form-sets-state="deleted"]'); if (deleteButton) deleteButton.click(); }); })- Open your Last.fm account's library while being logged in (https://www.last.fm/user/_/library).
- Type
javascript:into the address bar and paste the script directly after it. Or, open the dev tools and paste the script into the console. - Press enter. This will remove all duplicates on the current page.
- Let the site reload (invoked by the script).
- Repeat pasting the script and pressing enter if more duplicates appear at the bottom.
- If needed, go to the next page of your library repeat the steps as of step 3.
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.