GoogleブックマークをすっきりさせるGreasemonkeyスクリプト

スペース節約、横スクロールバー回避。

querySelectorAllを使っているので、Firefox 3.5以降でないと動かない。

// ==UserScript==
// @name           Google Bookmarks Simplifier
// @namespace      http://d.hatena.ne.jp/rikuba/
// @include        http://www.google.com/bookmarks/*
// @version        0.1
// ==/UserScript==

// 検索フォームを左上端に移動する
var searchForm = document.forms.namedItem("smhf");
document.getElementsByTagName("TABLE")[0].rows[0].firstChild.appendChild(searchForm);

// Googleロゴを消す
document.getElementsByTagName("TABLE")[1].style.display = "none";

// 左上の「ブックマーク」をブックマークのトップページへのリンクにする
var font = document.evaluate('/html/body/table[3]/tbody/tr[2]/td/font[2]',document,null,7,null).snapshotItem(0);
var a = document.createElement('A');
a.href = 'http://www.google.com/bookmarks/';
a.style.textDecoration = 'none';
a.appendChild(font.firstChild);
font.appendChild(a);

// 並べ替えのリンク群を少し上に移動する
document.evaluate('/html/body/table[4]/tbody/tr[2]/td[4]/table[1]',document,null,7,null).snapshotItem(0).style.marginTop = '-33px';

// サイドバーのウェブ履歴などを消す
var rws = document.getElementsByTagName('TABLE')[4].rows;
for(var i=0; i<24; i++) {
	rws[i].style.display = 'none';
}

// 各アイテム間の空行を削除
var emptyTrs = document.evaluate('//table[@class="res"]/tbody/tr[not(@id)]',document,null,7,null);
var tbdy = document.evaluate('//table[@class="res"]/tbody',document,null,7,null).snapshotItem(0);
for(var i=0, l=emptyTrs.snapshotLength; i<l; i++){
	tbdy.removeChild(emptyTrs.snapshotItem(i));
}

// 各アイテムの「ドメイン・日付・編集/削除」を次の行に移動する
var fnc = function(doc) {
	var tbls = doc.querySelectorAll('table[class="elem noborder"]');
	var tbl, newTbl, j;
	for(var i=0, l=tbls.length; i<l; i++){
		tbl = tbls.item(i);
		newTbl = tbl.cloneNode(true);
		tbl.parentNode.appendChild(newTbl);
		for(j=1; j<6; j++){
			tbl.rows[0].removeChild(tbl.rows[0].cells[1]);
		}
		newTbl.rows[0].removeChild(newTbl.rows[0].cells[0]);
		newTbl.rows[0].removeChild(newTbl.rows[0].cells[0]);
	}
}
fnc(document);
if (window.AutoPagerize) {
	window.AutoPagerize.addFilter(function(docs){
		docs.forEach(fnc);
	});
}

// CSSを追加
GM_addStyle(<><![CDATA[
	table.res > tbody > tr > td {
		padding: 0 0 0.5em !important;
	}
	table.elem td[nowrap] {
		white-space: normal !important;
	}
	.elem {
		font-size: 90% !important;
		line-height: 1.5 !important;
	}
	a[id^="bkmk_href_"] {
		font-size: 111.1% !important;
	}
]]></>);

ノードの取得の仕方に無駄が多い気がする。まだdocument.evaluateをよく理解できていない。
それにしても、Googleブックマークはテーブルの入れ子が凄まじい