クリックしたまたはの列に色を付けるBookmarklet

実行後、THタグまたはTDタグをクリックすると、確認のダイアログが出るので、「はい」を押すとその列に色がつきます。
「いいえ」を押した場合は再度クリックしてください。
THタグまたはTDタグ以外をクリックした場合は何もせず処理を終了します。

Google Chrome 3.0.195.33で動作確認。

※注1:IEでは動きません(document.evaluateを使用しているため)
注2:とても長いのでブラウザによってはURL長の制限で実行できない可能性があります。


ソース

javascript:
window.addEventListener('mousedown',function(e){
	var e=e.target,n=e.nodeName,k=0,i=0,r,x,c;
	if(/t[dh]/i.test(n)){
		if(!confirm('この列でいいですか?'))return;
		
		x=e.parentNode.getElementsByTagName(n);
		c=x.length;
		while(x.item(k++)!=e);
		
		r=document.evaluate('../../tr[count(th)='+c+']/th['+k+']|../../tr[count(td)='+c+']/td['+k+']',e,null,7,null);
		while(x=r.snapshotItem(i++))
			x.style.backgroundColor='yellow';
	}
	window.removeEventListener('mousedown',arguments.callee,true);
},true);
void(0)


1行にまとめたバージョン (はてな記法の関係でリンクの貼り方が分らないのでそのまま書きました)

javascript:window.addEventListener('mousedown',function(e){var e=e.target,n=e.nodeName,k=0,i=0,r,x,c;if(/t[dh]/i.test(n)){if(!confirm('この列でいいですか?'))return;x=e.parentNode.getElementsByTagName(n);c=x.length;while(x.item(k++)!=e);r=document.evaluate('../../tr[count(th)='+c+']/th['+k+']|../../tr[count(td)='+c+']/td['+k+']',e,null,7,null);while(x=r.snapshotItem(i++))x.style.backgroundColor='yellow';}window.removeEventListener('mousedown',arguments.callee,true);},true);void(0)


以下はいちいち確認ダイアログ出さなくていいよって人用。


ソース

javascript:
window.addEventListener('mousedown',function(e){
	var e=e.target,n=e.nodeName,k=0,i=0,r,x,c;
	if(/t[dh]/i.test(n)){
		x=e.parentNode.getElementsByTagName(n);
		c=x.length;
		while(x.item(k++)!=e);
		
		r=document.evaluate('../../tr[count(th)='+c+']/th['+k+']|../../tr[count(td)='+c+']/td['+k+']',e,null,7,null);
		while(x=r.snapshotItem(i++))
			x.style.backgroundColor='yellow';
	}
	window.removeEventListener('mousedown',arguments.callee,true);
},true);
void(0)


1行にまとめたバージョン

javascript:window.addEventListener('mousedown',function(e){var e=e.target,n=e.nodeName,k=0,i=0,r,x,c;if(/t[dh]/i.test(n)){x=e.parentNode.getElementsByTagName(n);c=x.length;while(x.item(k++)!=e);r=document.evaluate('../../tr[count(th)='+c+']/th['+k+']|../../tr[count(td)='+c+']/td['+k+']',e,null,7,null);while(x=r.snapshotItem(i++))x.style.backgroundColor='yellow';}window.removeEventListener('mousedown',arguments.callee,true);},true);void(0)