Skip to content

Instantly share code, notes, and snippets.

@SMUsamaShah
Last active March 3, 2025 07:51
Show Gist options
  • Select an option

  • Save SMUsamaShah/dfcc6f709158b0adcc0a48c2d66fd353 to your computer and use it in GitHub Desktop.

Select an option

Save SMUsamaShah/dfcc6f709158b0adcc0a48c2d66fd353 to your computer and use it in GitHub Desktop.
Gmail sort by sender bookmarklet (drag the code to bookmark bar)
javascript:(function() {
function sortEmailsBySender() {
var emails = Array.from(document.querySelectorAll('.zA'));
emails.sort(function(a, b) {
var senderA = a.querySelector('.yW span').innerText.toLowerCase();
var senderB = b.querySelector('.yW span').innerText.toLowerCase();
return senderA.localeCompare(senderB);
});
emails.forEach(function(email) {
email.parentNode.appendChild(email);
});
}
sortEmailsBySender();
})();
@shadsnz
Copy link
Copy Markdown

shadsnz commented Mar 2, 2025

Hi SMUsamaShah,
I'm trying to run this but it doesn't seem to sort the emails. I tested the very first version and it does sort but when you open the email its the original message from that position.

So these newer versions are obviously better but don't seem to work for me. I checked the console messages and it does seem to be triggering but doesn't change the emails shown.

Any suggestions on what I might have missed?

Thanks

@SMUsamaShah
Copy link
Copy Markdown
Author

@shadsnz Did you remove all the comments when using it as bookmarklet?

@shadsnz
Copy link
Copy Markdown

shadsnz commented Mar 2, 2025

Yes, I did. I'm using Chrome, have tested in both the Gmail Inbox, Sent and All Mail folders. I might try a different browser and another Gmail account to test.

@shadsnz
Copy link
Copy Markdown

shadsnz commented Mar 3, 2025

Well, it seems to work sometimes now after refreshing browsers and increasing the number of messages per page. Thanks for posting the code.

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