« TypePad 1.5 用 Atom 1.0 テンプレート (試作) | トップページ | 電子書籍販売サイト ΣBookJp の商品リンク »
2005.07.21
右クリックで「モヒカン族」 (改訂版)
最終更新: 2005年7月21日 21時
久しぶりに「モヒカン族に関する言及」に投稿しようとしたら、投稿失敗。はてなグループの掲示板もいつの間にかCSRF対策(いわゆる「ぼく、はまちちゃん」対策)が実施されたようで、投稿に失敗したのは、hiddenパラメータが1個追加されているのが原因でした。
ということで、「右クリックで はてなブックマーク、ついでに del.icio.us (2005年7月版)」と同様の対処を行なうよう、『右クリックで「モヒカン族」』スクリプトを書き直してみました。
以前の『右クリックで「モヒカン族」』スクリプトをお使いの方(っているのでしょうか?)は、差し替えをお願いします。
なお、「右クリックで はてなブックマーク、ついでに del.icio.us (2005年7月版)」と同様、外部 Javascript として、“Paj’s Home: Cryptography: JavaScript MD5” にて公開されている md5.js を利用しています。『右クリックで「モヒカン族」』スクリプトと同じディレクトリ(フォルダ)に、md5.js をダウンロードして、置いておいてください。
変更履歴
- 1.2版 2005年7月21日 夜 「はてな」の cookie の仕様変更に対応
- 1.1版 2005年7月21日 昼 「改訂版」を公開
ソース
それでは、以下、ソースです。(本スクリプトによる投稿例: モヒカン族 - 「モヒカン族」に関する言及 - 心眼メソッド)
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="md5.js"></script> <script type="text/javascript" language="JavaScript"> // 「右クリックで モヒカン族」 // written by H.Tsujimura (tsupo@na.rim.or.jp) // // モヒカン族掲示板に報告を投稿するためのスクリプトです。 // 殺伐と言及チェックしようぜ!! // // Version 1.2 21 Jul 2005 「はてなブックマーク」で使っているcookie の中 // 身の変更(追加)と同等の仕様変更が行なわれても追 // 随できるようにしてみた // Version 1.1 21 Jul 2005 CSRF対策後のはてなグループ掲示板に対応 // Version 1.0 7 Jul 2005 最初の版 // 注意: (1) このスクリプトを利用するには、「はてなグループ - モヒカン族」に // 参加する必要があります。 // はてなグループ - モヒカン族 http://mohican.g.hatena.ne.jp/ // (2) 本スクリプトを使用するにあたって、あらかじめ // Paj’s Home: Cryptography: JavaScript MD5 // (http://pajhome.org.uk/crypt/md5/index.html) // にて公開されている // md5.js // (ソース本体: http://pajhome.org.uk/crypt/md5/md5.js) // (ソースリスト: http://pajhome.org.uk/crypt/md5/md5src.html) // をダウンロードして、本スクリプトと同じディレクトリ(フォルダ) // に設置しておいてください。 // (3) 本スクリプトは、はてなにログインしている状態でお使いください。 obj = external.menuArguments; // 右クリック時の引数のオブジェクトの参照 page_url = obj.document.URL; // ページのURL title_txt = obj.document.title; // タイトル文字列 cite_txt = obj.document.selection.createRange().text; // 引用文字列 cite_html = obj.document.selection.createRange().htmlText; inn = obj.document.body.innerHTML; inn_html = obj.document.body.createTextRange().htmlText; if ( obj.location.href && (obj.location.href != "") ) page_url = obj.location.href; // 「はてなダイアリーキーワード」対策 txt = ""; function getTarget() { rest = txt; s = txt.indexOf("<"); while ( (s >= 0) && (s <= 2) ) { e = txt.indexOf(">"); txt = txt.substring(e+1,txt.length); s = txt.indexOf("<"); } if ( s > 0 ) { target = txt.substring(0,s); rest = txt.substring(s,txt.length); } else { target = txt; rest = ""; } txt = rest; return ( target ); } function adjustTarget(target) { /* for Bloglines */ q = target.indexOf('"'); // " if ( q > 0 ) target = target.substring(0,q); else if ( q == 0 ) target = target.substring(1,target.length); q = target.indexOf(' '); if ( q > 0 ) target = target.substring(0,q); else if ( q == 0 ) target = target.substring(1,target.length); q = target.indexOf('\\x0A'); if ( q > 0 ) target = target.substring(0,q); else if ( q == 0 ) target = target.substring(4,target.length); q = target.indexOf('\\x0D'); if ( q > 0 ) target = target.substring(0,q); else if ( q == 0 ) target = target.substring(4,target.length); do { q = target.indexOf('/'); if ( q >= 0 ) target = target.substring(0,q) + '\\x2F' + target.substring(q+1,target.length); else break; } while ( true ); return ( target ); } if ( (cite_txt != "") && (cite_txt.length > 0) ) { if ( page_url.match("http://www.bloglines.com/myblogs_display") || page_url.match("http://bloglines.com/myblogs_display") ) { /* Bloglines で読んでいるテキスト(記事、クリップ、など)を取り込み可能にするための処理 */ target1 = ""; target2 = ""; target3 = ""; target4 = ""; target5 = ""; if ( cite_txt == cite_html ) target1 = cite_txt; else { /* target1 */ txt = cite_html; target1 = getTarget(); cite_html = txt; if ( target1 != "" ) { target1 = adjustTarget(target1); txt = cite_html; target2 = getTarget(); cite_html = txt; } if ( target2 != "" ) { target2 = adjustTarget(target2); txt = cite_html; target3 = getTarget(); cite_html = txt; } if ( target3 != "" ) { target3 = adjustTarget(target3); txt = cite_html; target4 = getTarget(); cite_html = txt; } if ( target4 != "" ) { target4 = adjustTarget(target4); txt = cite_html; target5 = getTarget(); cite_html = txt; } if ( target5 != "" ) { target5 = adjustTarget(target5); } } loc = 0; aim = inn; done = false; s_summary = 0; do { s_summary = aim.indexOf("itemText+=\"<p><table cellspacing=0 cellpadding=0 width=\\\"100%\\\">"); if ( s_summary >= 0 ) { e_summary = aim.indexOf("itemText+=\"<div class=\\\"item_links\\\">\";",s_summary); if ( s_summary < e_summary ) { aim2 = aim.substring(s_summary+64,e_summary); if ( aim2.indexOf("\\x3C") == -1 ) { // 主として「人力検索サイトはてな」対策 // -- ちなみに、aim2.indexOf("\\x3C") >= 0 になるのは、MM/Memo とか はてなブックマーク -- // -- とか 記事本文(冒頭)が a 要素、blockquote要素等でマークアップされている場合 -- txt = aim2; aim2 = getTarget(); aim2 = adjustTarget(aim2); // 注意: 上記処理の結果、aim2.length < target?.length となる可能性が発生 } if ( (aim2.indexOf(target1) == -1) && (target1.indexOf(aim2) == -1) ) { aim = aim.substring(e_summary+39,aim.length); loc += (e_summary+39); continue; } if ( (target2 != "") && (aim2.indexOf(target2) == -1) && (target2.indexOf(aim2) == -1) ) { aim = aim.substring(e_summary+39,aim.length); loc += (e_summary+39); continue; } if ( (target3 != "") && (aim2.indexOf(target3) == -1) && (target3.indexOf(aim2) == -1) ) { aim = aim.substring(e_summary+39,aim.length); loc += (e_summary+39); continue; } if ( (target4 != "") && (aim2.indexOf(target4) == -1) && (target4.indexOf(aim2) == -1) ) { aim = aim.substring(e_summary+39,aim.length); loc += (e_summary+39); continue; } if ( (target5 != "") && (aim2.indexOf(target5) == -1) && (target5.indexOf(aim2) == -1) ) { aim = aim.substring(e_summary+39,aim.length); loc += (e_summary+39); continue; } done = true; } else break; } else break; } while ( done == false ); if ( s_summary > 0 ) { if ( loc >= 0 ) { locH3 = inn.substring(0,loc+s_summary).lastIndexOf("a title=\\\"サイト"); // " if ( locH3 == -1 ) locH3 = inn.substring(0,loc+s_summary).lastIndexOf("a title=\\\"Site"); // " if ( locH3 > 0 ) { targetString = inn.substring(locH3,loc+s_summary); siteName = ""; s_siteName = targetString.indexOf(": "); e_siteName = targetString.indexOf("\\\" href="); if ( (s_siteName > 0) && (s_siteName < e_siteName) ) siteName = targetString.substring(s_siteName+2,e_siteName); if ( targetString.match( "</a>") == null ) targetString = inn.substring(locH3,locH3+inn.substring(locH3,inn.length).indexOf("</a>")+4); locHREF = targetString.indexOf("href="); if ( locHREF > 0 ) { targetHREF = targetString.substring(locHREF + 7,targetString.indexOf('\\" target=')); s = targetString.indexOf('" target=_blank>'); e = targetString.indexOf("</a>"); if ( (s > 0) && (s < e) ) targetTITLE = targetString.substring(targetString.indexOf('" target=_blank>')+16,targetString.indexOf("</a>")); else targetTITLE = ""; if ( targetHREF != "" ) page_url = targetHREF; if ( targetTITLE != "" ) { if ( siteName != "" ) title_txt = siteName + ': ' + targetTITLE; else title_txt = targetTITLE; } } } } } } else if ( page_url.match( "http://r.hatena.ne.jp/" ) ) { /* はてなRSS で読んでいるテキスト(記事、クリップ、など)を取り込み可能にするための処理 */ target1 = ""; target2 = ""; target3 = ""; target4 = ""; target5 = ""; if ( cite_txt == cite_html ) target1 = cite_txt; else { /* target1 */ txt = cite_html; target1 = getTarget(); cite_html = txt; if ( target1 != "" ) { txt = cite_html; target2 = getTarget(); cite_html = txt; } if ( target2 != "" ) { txt = cite_html; target3 = getTarget(); cite_html = txt; } if ( target3 != "" ) { txt = cite_html; target4 = getTarget(); cite_html = txt; } if ( target4 != "" ) { txt = cite_html; target5 = getTarget(); cite_html = txt; } } loc = 0; aim = inn; done = false; s_summary = 0; do { s_summary = aim.indexOf("<DIV class=summary>"); if ( s_summary >= 0 ) { e_summary = aim.indexOf("</DIV>",s_summary); if ( s_summary < e_summary ) { aim2 = aim.substring(s_summary+19,e_summary); if ( aim2.indexOf(target1) == -1 ) { aim = aim.substring(e_summary+6,aim.length); loc += (e_summary+6); continue; } if ( (target2 != "") && (aim2.indexOf(target2) == -1) ) { aim = aim.substring(e_summary+6,aim.length); loc += (e_summary+6); continue; } if ( (target3 != "") && (aim2.indexOf(target3) == -1) ) { aim = aim.substring(e_summary+6,aim.length); loc += (e_summary+6); continue; } if ( (target4 != "") && (aim2.indexOf(target4) == -1) ) { aim = aim.substring(e_summary+6,aim.length); loc += (e_summary+6); continue; } if ( (target5 != "") && (aim2.indexOf(target5) == -1) ) { aim = aim.substring(e_summary+6,aim.length); loc += (e_summary+6); continue; } done = true; } else break; } else break; } while ( done == false ); if ( s_summary > 0 ) { loc = inn.substring(0,loc+s_summary).lastIndexOf("<H3>"); if ( loc >= 0 ) { txt = inn.substring(loc+4,inn.length); targetHREF = txt.substring(txt.indexOf("href=\"")+6,txt.indexOf("\" target=_blank")); targetTITLE = getTarget(); if ( targetHREF != "" ) page_url = targetHREF; if ( targetTITLE != "" ) title_txt = targetTITLE; } } } else if ( page_url.match( "http://www.google.co.jp/search" ) ) { /* Google の検索結果を元に、元記事を参照することなくクリップするための処理 */ /* -- LostGoogles をインストールしている環境でも動作確認済み */ /* cite_html は正規化済み(IEの場合)なのに対し、inn の方はオリジナルの html ソース */ /* のままなので、そのまま文字列比較はできないため、比較できる形式に cite_html を変 */ /* 形する (本当は、DOM を使ってあれこれすべき) */ while ( cite_html.match( "</FONT>" ) ) { f = cite_html.indexOf( "</FONT>" ); cite_html = cite_html.substring(0,f) + cite_html.substring(f+7,cite_html.length); } if ( cite_html.match( "\n" ) ) { f = cite_html.indexOf( "\n" ); cite_html = cite_html.substring(0,f-1); } /* * locG locHREF locTitle * | | | * v v v * <p class=g><a href="元記事URL" onmousedown="return clk(this,'res',11,'')">元記事タイトル</a> * (検索キーワードと一致する部分は <b> ~ </b> で囲まれている) */ loc = inn.indexOf(cite_html); if ( loc >= 0 ) { sub = inn.substring(0,loc); locG = sub.lastIndexOf("<P class=g>"); if ( locG >= 0 ) { sub = sub.substring(locG+11,loc); locHREF = sub.indexOf("href=\""); if ( locHREF >= 0 ) { sub = sub.substring(locHREF+6,sub.length); targetHREF = sub.substring(0,sub.indexOf('"')); targetTITLE = ""; locTitle = sub.indexOf("\">"); if ( locTitle >= 0 ) { locTitle += 2; sub = sub.substring(locTitle,sub.length); locEnd = sub.indexOf("</A>"); if ( locEnd >= 0 ) { targetTITLE = sub.substring(0,locEnd); /* <B> ~ </B> を除去 */ while ( targetTITLE.match( "<B>" ) || targetTITLE.match( "</B>" ) ) { b1 = targetTITLE.indexOf( "<B>" ); if ( b1 >= 0 ) targetTITLE = targetTITLE.substring(0,b1) + targetTITLE.substring(b1+3,targetTITLE.length); b2 = targetTITLE.indexOf( "</B>" ); if ( b2 >= 0 ) targetTITLE = targetTITLE.substring(0,b2) + targetTITLE.substring(b2+4,targetTITLE.length); } } } if ( targetHREF != "" ) page_url = targetHREF; if ( targetTITLE != "" ) title_txt = targetTITLE; } } } } } if ( title_txt == "[object]" ) { /* title に '*' が含まれている場合にうまく取り込めない現象への対策 */ str = obj.document.body.parentNode; inn = str.innerHTML; s = inn.indexOf("<TITLE>"); e = inn.indexOf("</TITLE>"); if ( (s > 0) && (e > s) ) title_txt = inn.substring(s + 7, e); } page_str = ""; len = page_url.length; for ( i = 0; i < len; i++ ) { if ( page_url.charAt(i) == '&' ) page_str += "&"; else page_str += page_url.charAt(i); } x = prompt("コメント","ノーコメント"); y = prompt("タイトル","モヒカン族に関する言及"); newWin = window.open("http://mohican.g.hatena.ne.jp/bbs/2#edit","mohican"); t = newWin.document.cookie; loc = t.lastIndexOf(';'); if ( loc > 0 ) rk = t.substring(0,t.lastIndexOf(';')); /* 2005年7月21日 夕方以降 */ else rk = t; /* 2005年7月21日 夕方まで */ rk = rk.substring(rk.lastIndexOf('=')+1); rkm = b64_md5(rk); // newWin.close(); // newWin = window.open("http://mohican.g.hatena.ne.jp/bbs/2#edit","mohican"); newWin.document.open(); newWin.document.write('<html>\n'); newWin.document.write('<head>\n'); newWin.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n'); newWin.document.write('<meta http-equiv="Content-Style-Type" content="text/css">\n'); newWin.document.write('<meta http-equiv="Content-Script-Type" content="text/javascript">\n'); newWin.document.write('<link rel="stylesheet" href="http://mohican.g.hatena.ne.jp/theme/hatena-black/hatena-black.css" type="text/css" media="all" charset="euc-jp">\n'); newWin.document.write('<title>モヒカン族への言及 投稿画面</title>\n'); newWin.document.write('</head>\n'); newWin.document.write('<body>\n'); newWin.document.write('<div class="hatena-body">\n'); newWin.document.write('<div class="day">\n'); newWin.document.write('<form method="post" action="http://mohican.g.hatena.ne.jp/bbs" name="edit">\n'); newWin.document.write('<input type="hidden" name="mode" value="enter">\n'); newWin.document.write('<input type="hidden" name="rkm" value="' + rkm + '">\n'); newWin.document.write('<input type="hidden" name="tid" value="2">\n'); newWin.document.write('<h2><span class="title"><input type="text" name="title" size=40 value="' + y + '"></span></h2>\n'); newWin.document.write('<div class="body">\n'); newWin.document.write('<textarea cols="60" rows="20" name="body">' + '-' + title_txt + '\n' + page_str + '\n>>\n' + cite_txt + '\n<<\n' + x + '</textarea><br>\n'); newWin.document.write('<p class="footnote">※はてな記法が使用できます。</p>\n'); newWin.document.write('<input type="submit" value="この内容を書き込む">\n'); newWin.document.write('<input type="checkbox" name="trivial" value="1"><span style="font-size: smaller;">ちょっとした書き込み</span>\n'); newWin.document.write('</div>\n'); newWin.document.write('</form>\n'); newWin.document.write('</div>\n'); newWin.document.write('</div>\n'); newWin.document.write('</body>\n'); newWin.document.write('</html>\n'); newWin.document.close(); newWin.focus(); </script>
投稿者: tsupo 2005.07.21 午前 11:54
| 固定リンク
|
|
|
|
|
アマゾンわくわく探検隊
トラックバック
この記事のトラックバックURL:
この記事へのトラックバック一覧です: 右クリックで「モヒカン族」 (改訂版):