/ Published in: JavaScript
This is a very simple bookmarklet that will temporarily sort the *visible* messages in Gmail by subject. You'll have to run it again each time Gmail refreshes the list.
[Sort Gmail Messages](javascript:(function(){function%20f(r){var%20t=r.getElementsByTagName("td");var%20d,s;var%20i,j;for(i=0;i
[Sort Gmail Messages](javascript:(function(){function%20f(r){var%20t=r.getElementsByTagName("td");var%20d,s;var%20i,j;for(i=0;i
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/**************************************** A very simple bookmarklet that will temporarily sort the *visible* messages in Gmail by subject. You'll have to run it again each time Gmail refreshes the list. There are a few caveats when the list is sorted: 1. Shift-clicking to select multiple messages will no longer work. 2. If you archive or delete messages, they will not disappear. /****************************************/ javascript:(function(){function%20f(r){var%20t=r.getElementsByTagName("td");var%20d,s;var%20i,j;for(i=0;i<t.length;i++){if(t[i].hasAttribute("role")&&t[i].getAttribute("role")=="link"){d=t[i].getElementsByTagName("div");for(j=0;j<d.length;j++){if(d[j].className=="y6"){s=d[j].getElementsByTagName("span");if(s.length)return%20s[0].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%20d=document.getElementById('canvas_frame').contentWindow.document;var%20t=d.getElementsByTagName('table');for(var%20i=0;i<t.length;i++){if(t[i].className=='F%20cf%20zt'){sl(t[i]);break}}})() //Expanded: javascript:(function(){ function findTitle(r) { var td = r.getElementsByTagName("td"); var div, span; var i, j; for(i=0; i<td.length; i++) { if(td[i].hasAttribute("role") && td[i].getAttribute("role") == "link") { div = td[i].getElementsByTagName("div"); for(j=0; j<div.length; j++) { if(div[j].className == "y6") { span = div[j].getElementsByTagName("span"); if(span.length) return span[0].innerHTML; } } } } return ""; } function doSort(a,b) { a = a[0].toLowerCase(); b = b[0].toLowerCase(); if(a<b) return -1; if(a>b) return 1; return 0; } function sortList(m) { var list = Array.prototype.slice.call(m.getElementsByTagName("tr"), 0); if(!list.length) return; var tbody = list[0].parentNode; var sortList = []; for(var i=0; i<list.length; i++) { sortList[i] = [findTitle(list[i]),list[i]]; } sortList = sortList.sort(doSort); for(i=0; i<sortList.length; i++) { tbody.appendChild(sortList[i][1]); } } var doc = document.getElementById('canvas_frame').contentWindow.document; var tables = doc.getElementsByTagName('table'); for(var i=0; i<tables.length; i++) { if(tables[i].className=='F cf zt') { sortList(tables[i]); break; } } })()