全テキストを取得

ブックマークレット作成の為の第1step。ページ中の全てのテキストを取得するjavascript
某掲示板の回答を参考に…というか、まんまです。(;・∀・)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="content-script-type" content="text/javascript">
<meta http-equiv="content-style-type" content="text/css">
<script type="text/javascript">
window.onload = function() {
  var result = []; var n;
  for (n = document.getElementsByTagName('BODY')[0]; n; ) {
    if (n.nodeType == 3) alert(n.nodeValue);
    if (n.firstChild) { n = n.firstChild; continue; }
    do if (n.nextSibling) { n = n.nextSibling; break; } while (n = n.parentNode);
  }
}
</script>
<title>全テキストノード取得</title>
</head>
<body>
<p>あああああ</p>
<p>いいいい</p>
<p>ううう</p>
<p>ええ</p>
<p></p>
</body>
</html>

「あああああ」やら「ううう」やらがalertで表示されます。IEでは、タグ内のテキスト部分のみalert表示されますが、
OperaFirefoxは、改行文字やタブも「テキストノード」として扱われるので、
空(実際は改行文字)のalertが表示されますが、これもFirefoxOperaの振る舞いの方が寧ろ正しいみたいです。

という訳で、後はこいつを元に苦手な正規表現使って特定のキーワードを置換する様にすれば
ブックマークレットは完成なので、もうすぐお披露目できるかな?