Return to Snippet

Revision: 10216
at March 9, 2010 10:07 by wizard04


Updated Code
/****************************************
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;
	}
}

})()

Revision: 10215
at March 9, 2010 09:22 by wizard04


Updated Code
/****************************************
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;
	}
}

})()

Revision: 10214
at March 9, 2010 09:18 by wizard04


Updated Code
/****************************************
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.
****************************************/

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;
	}
}

})()

Revision: 10213
at October 28, 2009 09:37 by wizard04


Updated Code
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;
	}
}

})()

Revision: 10212
at August 27, 2009 09:02 by wizard04


Updated Code
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%20m=document.getElementById('canvas_frame').contentWindow.document.getElementById(":op");if(m)sl(m)})()



//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 messages = document.getElementById('canvas_frame').contentWindow.document.getElementById(":op");
if(messages) sortList(messages);


})()

Revision: 10211
at August 12, 2009 08:50 by wizard04


Updated Code
javascript:(function(){function f(r){var t=r.getElementsByTagName("td");var d,s;var i,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 s[0].innerHTML}}}}return ""}function ds(a,b){a=a[0].toLowerCase();b=b[0].toLowerCase();if(a<b)return -1;if(a>b)return 1;return 0}function sl(m){var l=Array.prototype.slice.call(m.getElementsByTagName("tr"),0);if(!l.length)return;var b=l[0].parentNode;var s=[];for(var i=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 m=document.getElementById('canvas_frame').contentWindow.document.getElementById(":op");if(m)sl(m)})()



//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 messages = document.getElementById('canvas_frame').contentWindow.document.getElementById(":op");
if(messages) sortList(messages);


})()

Revision: 10210
at July 9, 2009 13:06 by wizard04


Updated Code
javascript:(function(){function f(r){var t=r.getElementsByTagName("td");var d,s;var i,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 s[0].innerHTML}}}}return ""}function ds(a,b){a=a[0].toLowerCase();b=b[0].toLowerCase();if(a<b)return -1;if(a>b)return 1;return 0}function sl(m){var l=Array.prototype.slice.call(m.getElementsByTagName("tr"),0);if(!l.length)return;var b=l[0].parentNode;var s=[];for(var i=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 m=document.getElementById('canvas_frame').contentWindow.document.getElementById(":ou");if(m)sl(m)})()



//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 messages = document.getElementById('canvas_frame').contentWindow.document.getElementById(":ou");
if(messages) sortList(messages);


})()

Revision: 10209
at December 15, 2008 16:00 by wizard04


Updated Code
javascript:(function(){function findClass(d,c){var e,i;for(i=0;i<d.childNodes.length;i++){e=d.childNodes[i];if(e.className&&e.className.indexOf(c)>=0)return e;else{if(e=findClass(e,c))return e}}return null}function sortList(t){var ms=[],i,j,m=0,d,r=t.getElementsByTagName('tr');for(i=0;i<r.length;i++){d=r[i].getElementsByTagName('div');for(j=0;j<d.length;j++){if(d[j].className=='HhG5wd'){ms[i]={};ms[i].s=d[j].firstChild.innerHTML.toLowerCase();ms[i].r=r[i];m++}}}if(m>0){t=ms[0].r.parentNode;var c;for(i=m-1;i>0;i--){c=0;for(j=1;j<=i;j++){if(ms[j].s<ms[c].s)c=j}t.appendChild(ms[c].r);ms.splice(c,1)}t.appendChild(ms[0].r)}}var i,t,d,c=0;t=findClass(document.getElementById('canvas_frame').contentWindow.document,'q0CeU').getElementsByTagName('table');d=t[0].parentNode.parentNode.parentNode.parentNode;if(t[0].getElementsByTagName('col').length>3)d=d.parentNode;d=d.childNodes;for(i=1;i<d.length;i++){t=d[i].getElementsByTagName('table')[0];if(d[i].style.display==''){sortList(t);c++}}if(!c)sortList(d[0].getElementsByTagName('table')[0]);})()


//Expanded:

javascript:(function(){

function findClass(d,c)
{
	var e,i;
	for(i=0;i<d.childNodes.length;i++)
	{
		e=d.childNodes[i];
		if(e.className&&e.className.indexOf(c)>=0)return e;
		else
		{
			if(e=findClass(e,c))return e
		}
	}
	return null
}
function sortList(t)
{
	var ms=[],i,j,m=0,d,r=t.getElementsByTagName('tr');
	for(i=0;i<r.length;i++)
	{
		d=r[i].getElementsByTagName('div');
		for(j=0;j<d.length;j++)
		{
			if(d[j].className=='HhG5wd')
			{
				ms[i]={};
				ms[i].s=d[j].firstChild.innerHTML.toLowerCase();
				ms[i].r=r[i];
				m++
			}
		}
	}
	if(m>0)
	{
		t=ms[0].r.parentNode;
		var c;
		for(i=m-1;i>0;i--)
		{
			c=0;
			for(j=1;j<=i;j++)
			{
				if(ms[j].s<ms[c].s)c=j
			}
			t.appendChild(ms[c].r);
			ms.splice(c,1)
		}
		t.appendChild(ms[0].r)
	}
}

var i,t,d,c=0;
t=findClass(document.getElementById('canvas_frame').contentWindow.document,'q0CeU').getElementsByTagName('table');
d=t[0].parentNode.parentNode.parentNode.parentNode;
if(t[0].getElementsByTagName('col').length>3)d=d.parentNode;
d=d.childNodes;
for(i=1;i<d.length;i++)
{
	t=d[i].getElementsByTagName('table')[0];
	if(d[i].style.display==''){sortList(t);c++}
}
if(!c)sortList(d[0].getElementsByTagName('table')[0]);


})()

Revision: 10208
at December 12, 2008 11:55 by wizard04


Updated Code
javascript:(function(){var x=function(){var l=document.getElementById(':li');var r=l.getElementsByTagName('tr');var ms=[],i,j,m=0,d;for(i=0;i<r.length;i++){d=r[i].getElementsByTagName('div');for(j=0;j<d.length;j++){if(d[j].className=='HhG5wd'){ms[i]={};ms[i].s=d[j].firstChild.innerHTML.toLowerCase();ms[i].r=r[i];m++}}}if(m>0){l=ms[0].r.parentNode;var c;for(i=m-1;i>0;i--){c=0;for(j=1;j<=i;j++){if(ms[j].s<ms[c].s)c=j}l.appendChild(ms[c].r);ms.splice(c,1)}l.appendChild(ms[0].r)}};var f=document.getElementById('canvas_frame');f.src='javascript:('+x+')();'})()


//Expanded:

javascript:(function(){

var x=function(){
	var l=document.getElementById(':li');	//table holding the list
	var r=l.getElementsByTagName('tr');	//all its rows (i.e., messages)
	var ms=[],i,j,m=0,d;
	for(i=0;i<r.length;i++)
	{
		d=r[i].getElementsByTagName('div');
		for(j=0;j<d.length;j++)
		{
			if(d[j].className=='HhG5wd')	//the subject div
			{
				ms[i]={};	//info about the message (its row & the subject text)
				ms[i].s=d[j].firstChild.innerHTML.toLowerCase();
				ms[i].r=r[i];
				m++
			}
		}
	}
	if(m>0)	//sort the messages
	{
		l=ms[0].r.parentNode;
		var c;
		for(i=m-1;i>0;i--)
		{
			c=0;
			for(j=1;j<=i;j++)
			{
				if(ms[j].s<ms[c].s)c=j
			}
			l.appendChild(ms[c].r);
			ms.splice(c,1)
		}
		l.appendChild(ms[0].r)
	}
};

var f=document.getElementById('canvas_frame');	//the iframe containing the message list
f.src='javascript:('+x+')();'

})()

Revision: 10207
at December 12, 2008 11:20 by wizard04


Updated Code
javascript:(function(){var x=function(){var l=document.getElementById(':li');var r=l.getElementsByTagName('tr');var ms=[],i,j,m=0,d;for(i=0;i<r.length;i++){d=r[i].getElementsByTagName('div');for(j=0;j<d.length;j++){if(d[j].className=='HhG5wd'){ms[i]={};ms[i].s=d[j].firstChild.innerHTML.toLowerCase();ms[i].r=r[i];m++}}}if(m>0){l=ms[0].r.parentNode;var c;for(i=m-1;i>0;i--){c=0;for(j=1;j<=i;j++){if(ms[j].s<ms[c].s)c=j}l.appendChild(ms[c].r);ms.splice(c,1)}l.appendChild(ms[0].r)}};var f=document.getElementById('canvas_frame');f.src='javascript:('+x+')();'})()


//Expanded:

javascript:(function(){

var x=function(){
	var l=document.getElementById(':li');
	var r=l.getElementsByTagName('tr');
	var ms=[],i,j,m=0,d;
	for(i=0;i<r.length;i++)
	{
		d=r[i].getElementsByTagName('div');
		for(j=0;j<d.length;j++)
		{
			if(d[j].className=='HhG5wd')
			{
				ms[i]={};
				ms[i].s=d[j].firstChild.innerHTML.toLowerCase();
				ms[i].r=r[i];
				m++
			}
		}
	}
	if(m>0)
	{
		l=ms[0].r.parentNode;
		var c;
		for(i=m-1;i>0;i--)
		{
			c=0;
			for(j=1;j<=i;j++)
			{
				if(ms[j].s<ms[c].s)c=j
			}
			l.appendChild(ms[c].r);
			ms.splice(c,1)
		}
		l.appendChild(ms[0].r)
	}
};

var f=document.getElementById('canvas_frame');
f.src='javascript:('+x+')();'

})()

Revision: 10206
at December 12, 2008 11:06 by wizard04


Updated Code
javascript:(function(){var x=function(){var l=document.getElementById(':li');var r=l.getElementsByTagName('tr');var ms=[],i,j,m=0,d;for(i=0;i<r.length;i++){d=r[i].getElementsByTagName('div');for(j=0;j<d.length;j++){if(d[j].className=='HhG5wd'){ms[i]={};ms[i].s=d[j].firstChild.innerHTML;ms[i].r=r[i];m++}}}if(m>0){l=ms[0].r.parentNode;var c;for(i=m-1;i>0;i--){c=0;for(j=1;j<=i;j++){if(ms[j].s<ms[c].s)c=j}l.appendChild(ms[c].r);ms.splice(c,1)}l.appendChild(ms[0].r)}};var f=document.getElementById('canvas_frame');f.src='javascript:('+x+')();'})()

Revision: 10205
at December 12, 2008 11:01 by wizard04


Initial Code
javascript:(function(){var x=function(){var l=document.getElementById(":li");var r=l.getElementsByTagName("tr");var ms=[],i,j,m=0,d;for(i=0;i<r.length;i++){d=r[i].getElementsByTagName("div");for(j=0;j<d.length;j++){if(d[j].className=="HhG5wd"){ms[i]={};ms[i].s=d[j].firstChild.innerHTML;ms[i].r=r[i];m++}}}if(m>0){l=ms[0].r.parentNode;var c;for(i=m-1;i>0;i--){c=0;for(j=1;j<=i;j++){if(ms[j].s<ms[c].s)c=j}l.appendChild(ms[c].r);ms.splice(c,1)}l.appendChild(ms[0].r)}};var f=document.getElementById("canvas_frame");f.src="javascript:("+x+")();"})()

Initial URL

                                

Initial Description
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(&#41;{function%20f(r&#41;{var%20t=r.getElementsByTagName(&#34;td&#34;&#41;;var%20d,s;var%20i,j;for(i=0;i<t.length;i++&#41;{if(t[i].hasAttribute(&#34;role&#34;&#41;&&t[i].getAttribute(&#34;role&#34;&#41;==&#34;link&#34;&#41;{d=t[i].getElementsByTagName(&#34;div&#34;&#41;;for(j=0;j<d.length;j++&#41;{if(d[j].className==&#34;y6&#34;&#41;{s=d[j].getElementsByTagName(&#34;span&#34;&#41;;if(s.length&#41;return%20s[0].innerHTML}}}}return%20&#34;&#34;}function%20ds(a,b&#41;{a=a[0].toLowerCase(&#41;;b=b[0].toLowerCase(&#41;;if(a<b&#41;return%20-1;if(a>b&#41;return%201;return%200}function%20sl(m&#41;{var%20l=Array.prototype.slice.call(m.getElementsByTagName(&#34;tr&#34;&#41;,0&#41;;if(!l.length&#41;return;var%20b=l[0].parentNode;var%20s=[];for(var%20i=0;i<l.length;i++&#41;{s[i]=[f(l[i]&#41;,l[i]]}s=s.sort(ds&#41;;for(i=0;i<s.length;i++&#41;{b.appendChild(s[i][1]&#41;}}var%20d=document.getElementById(&#39;canvas_frame&#39;&#41;.contentWindow.document;var%20t=d.getElementsByTagName(&#39;table&#39;&#41;;for(var%20i=0;i<t.length;i++&#41;{if(t[i].className==&#39;F%20cf%20zt&#39;&#41;{sl(t[i]&#41;;break}}}&#41;(&#41;
 "Drag this into your bookmarks!")

[roryok](http://snipplr.com/users/roryok/) found 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.

Initial Title
Sort Gmail Messages by Subject

Initial Tags
javascript, sort

Initial Language
JavaScript