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