Posted By

roryok on 10/27/09


Tagged

javascript sort gmail from bookmarklet


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wizard04


Sort Gmail Messages By Sender


 / Published in: JavaScript
 

This is based on the Sort Gmail Messages By Bookmarklet snippet.

Drag this into your Bookmarks: SortGmailBySender

A few caveats of this snippet (and the original)

  1. This will screw up your checkbox selection order. Shift clicking to select multiple messages will no longer work until you refresh the view
  2. If you archive or delete messages in this view, they will not disappear until you refresh gmail, but remember you can do a much lighter refresh by simply hitting the internal gmail 'refresh' link, rather than F5.
  3. I had to change the table selector from ":op" in the original to ":on" in the new version. gmail code changes regularly so you may have to tweak code a little.
  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  

You need to login to post a comment.