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!');
@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