How to Sort YouTube Music Playlist on a Web Browser
A quick hack to sort your YouTube Music Playlist temporarly.
- Press F12 or Right Click → Inspect to open Browser Developer Tools and select Developer Console.
Pro Tip: You can open Developer Console directly using the keyboard shortcut ctrl+shift+j (on Windows) or cmd+option+j (on Mac)
2. Paste following code snippet to Developer Console. To enable code pasting, you might need to allow it by typing allow pasting
first. Then proceed to paste the code and hit ENTER!
const container = document.querySelector('#contents.style-scope.ytmusic-playlist-shelf-renderer');
const items = Array.from(container.getElementsByTagName('ytmusic-responsive-list-item-renderer'));
items.sort((a, b) => {
const aText = a.querySelector('.title.style-scope.ytmusic-responsive-list-item-renderer.complex-string a').textContent;
const bText = b.querySelector('.title.style-scope.ytmusic-responsive-list-item-renderer.complex-string a').textContent;
return aText.localeCompare(bText);
});
while (container.firstChild) {
container.removeChild(container.firstChild);
}
items.forEach(item => container.appendChild(item));
That’s it! You can see the magic now.
Please note that the sorting is temporary and will reset once you reload the page. Class names and tag names may be changed in the future so that this fix will not work.
Hope YouTube Music will introduce sorting feature soon. Thanks for reading my article!