Skip to content

Instantly share code, notes, and snippets.

@elliotchance
Created March 19, 2023 21:00
Show Gist options
  • Save elliotchance/b10525b1cd636326c55fa23f46a22bd9 to your computer and use it in GitHub Desktop.
Save elliotchance/b10525b1cd636326c55fa23f46a22bd9 to your computer and use it in GitHub Desktop.
Sort list items by artist/title
let done;
do {
done = true;
Array.from(document.getElementsByClassName('box'))
.sort((a, b) => {
const [x, y] = [a.innerText, b.innerText];
const cmp = x.localeCompare(y);
if (cmp < 0) {
done = false;
document.getElementById(a.id).parentNode.insertBefore(document.getElementById(a.id), document.getElementById(b.id));
console.log(`Swapping ${x.trim()} and ${y.trim()}`);
}
return cmp;
});
} while (!done);
console.log('Done!');
@skorasaurus
Copy link

skorasaurus commented Jul 22, 2024

thanks so much; worked like a charm for a 1,500+ item list on chrome!

(for anyone who comes across this; this can be used to alphabetize lists within rateyourmusic.com

You must be in the editing interface of a list and have edit capabilities of the list; then paste this in your browser's console.

(This can obviously be customized for a variety of other situations as well).

@Binocularbath
Copy link

very good. doesnt work so well on firefox but works perfectly on chrome. Thanks for sharing

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