-
-
Save elliotchance/b10525b1cd636326c55fa23f46a22bd9 to your computer and use it in GitHub Desktop.
Sort list items by artist/title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); |
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
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).