Sort Gmail Messages By Sender


/ Published in: JavaScript
Save to your folder(s)

This is based on the [Sort Gmail Messages By Bookmarklet](http://snipplr.com/view/10432/sort-gmail-messages-by-subject/ "Sort Gmail Messages By Bookmarklet - http://snipplr.com/view/10432/sort-gmail-messages-by-subject/") snippet.


Drag this into your Bookmarks: [SortGmailBySender](javascript:(function(){function%20f(r){var%20t=r.getElementsByTagName("span");var%20i;for(i=0;i


Copy this code and paste it in your HTML
  1. javascript:(function(){function%20f(r){var%20t=r.getElementsByTagName("span");var%20i;for(i=0;i<t.length;i++){if(t[i].hasAttribute("email")){return%20t[i].innerHTML}}return%20""}function%20ds(a,b){a=a[0].toLowerCase();b=b[0].toLowerCase();if(a<b)return%20-1;if(a>b)return%201;return%200}function%20sl(m){var%20l=Array.prototype.slice.call(m.getElementsByTagName("tr"),0);if(!l.length)return;var%20b=l[0].parentNode;var%20s=[];for(var%20i=0;i<l.length;i++){s[i]=[f(l[i]),l[i]]}s=s.sort(ds);for(i=0;i<s.length;i++){b.appendChild(s[i][1])}}var%20m=document.getElementById('canvas_frame').contentWindow.document.getElementById(":on");if(m)sl(m)})()
  2.  
  3.  
  4. // Expanded Script
  5.  
  6. javascript:(function(){
  7.  
  8. function findFrom(r) {
  9.  
  10. var span = r.getElementsByTagName("span");
  11. var i;
  12. for (i = 0; i < span.length; i++) {
  13. if (span[i].hasAttribute("email")) {
  14. return span[i].innerHTML;
  15. }
  16. }
  17. return "";
  18.  
  19. }
  20. function doSort(a,b)
  21. {
  22. a = a[0].toLowerCase();
  23. b = b[0].toLowerCase();
  24. if(a<b) return -1;
  25. if(a>b) return 1;
  26. return 0;
  27. }
  28. function sortList(m)
  29. {
  30. var list = Array.prototype.slice.call(m.getElementsByTagName("tr"), 0);
  31. if(!list.length) return;
  32. var tbody = list[0].parentNode;
  33. var sortList = [];
  34. for(var i=0; i<list.length; i++)
  35. {
  36. sortList[i] = [findFrom(list[i]),list[i]];
  37. }
  38. sortList = sortList.sort(doSort);
  39. for(i=0; i<sortList.length; i++)
  40. {
  41. tbody.appendChild(sortList[i][1]);
  42. }
  43. }
  44.  
  45. var messages = document.getElementById('canvas_frame').contentWindow.document.getElementById(":on");
  46. if(messages) sortList(messages);
  47.  
  48.  
  49. })()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.