右クリックではてなブックマーク、ついでにdel.icio.us (はてなブックマーク「コレクション」対応版)

観測気球

収集物の記録書庫 a data archive of collection -- collectible toys

[要旨] いまさらのような気がしますが、はてなブックマークの「コレクション」に対応してみました。
[キーワード] ソーシャルブックマーク,JavaScript

« Gmail の1行広告に日本語の広告が登場 | トップページ | ブログ支援ソフトウェア「マイ・ブログ」 »

2006.04.04

右クリックではてなブックマーク、ついでにdel.icio.us (はてなブックマーク「コレクション」対応版)

約半年ぶりに「右クリックではてなブックマーク、ついでにdel.icio.us」の新しい版を作りました。この版で、いまさらのような気がしますが、はてなブックマークの「コレクション」に対応しました。

アマゾンの個別商品詳細ページや、はてなダイアリーのレビューページ(http://d.hatena.ne.jp/asin/ で URL が始まるページ)をブックマークしようとしたとき、ブックマークだけではなく、コレクションにも登録するかどうかを選択できます。

それだけでは何なので、ついでに、RSSリーダで読んでいるときに URL の末尾に ?ref=RSS のようなトラッキング用文字列が付くサイトがありますが、そのトラッキング用文字列を削除してから、ブックマークするようにしてみました。

ということで、以下にソースを示します。設置方法は、前のバージョンと同じです。すでに前のバージョンを使っている場合は、そのまま上書きするだけで OK です。

[観] 右クリックで はてなブックマーク、ついでに del.icio.us (はてな投げ銭対応版)

設置方法は今回も変わりません。つまり、

外部 Javascript として、“Paj’s Home: Cryptography: JavaScript MD5” にて公開されている md5.js を利用しています。「右クリックで はてなブックマーク、ついでに del.icio.us」スクリプトと同じディレクトリ(フォルダ)に、md5.js をダウンロードして、置いておいてください。

[観] 右クリックで はてなブックマーク、ついでに del.icio.us (2005年7月版)

ということです。

ソース

それでは、ソースです。

<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=EUC-JP">
<script type="text/javascript" src="md5.js"></script>
<script type="text/javascript" language="JavaScript">

// 「右クリックで はてなブックマーク、ついでに del.icio.us」
//     written by H.Tsujimura (tsupo@na.rim.or.jp)
//
//     注意: 本スクリプトを使用するにあたって、あらかじめ
//              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)
//           をダウンロードして、本スクリプトと同じディレクトリ(フォルダ)
//           に設置しておいてください。
//
//           また、Internet Explorer 6.0 SP2 以降をお使いの場合は、「はてな
//           ブックマーク」登録画面表示時に、セキュリティの警告が出ることが
//           あります。警告が出るたびに「コンテンツの実行を許可」してくださ
//           い。毎回「許可」するのが面倒だと思う方は、Internet Explorer の
//             ツール - インターネットオプション - 詳細設定
//           の「マイ コンピュータのファイルでのアクティブ コンテンツの実行
//           を許可する」をチェック状態にしてください。ただし、この設定変更
//           によりセキュリティ上の危険性が高まりますので、ご注意ください。
//
//     Version 4.1   4 Apr 2006  (1) 「はてなブックマーク」の「コレクション」
//                                   への追加をサポート
//                               (2) ブックマークしようとしている URL の末尾
//                                   に ?ref=rss のようなトラッキング文字列が
//                                   存在する場合は除去するようにした
//     Version 4.0  29 Sep 2005  「はてなブックマーク」のコメント欄編集時に
//                               (本スクリプト起動時にマウスで選択している文
//                               字列がある場合でも)コメントの長さを表示でき
//                               るようにした
//     Version 3.1  29 Sep 2005  Bloglines でうまく拾えないパターンをまた1つ
//                               つぶす
//     Version 3.0  15 Aug 2005  「はてなブックマーク」登録時に「はてな投げ
//                               銭」を実行できるようにした
//     Version 2.2  21 Jul 2005  「はてなブックマーク」で使っているcookie
//                               の中身が変更(追加)されたのに対応
//     Version 2.1  20 Jul 2005  Version 1.7 の修正を一部キャンセルし、元に
//                               戻す (Bloglines の生成する html が元に戻っ
//                               た?)
//     Version 2.0  15 Jul 2005  はてなブックマーク登録時の動作変更(仕様変
//                               更)に対応するため、大幅に処理を追加
//     Version 1.7  15 Jul 2005  Bloglines でうまく拾えないパターンが残っ
//                               ている原因(の1つ?)が判明、対策を実施
//     Version 1.6   7 Jul 2005  「はてなダイアリーキーワード」対策を実施
//     Version 1.5  28 Jun 2005  Bloglines で読んでいる記事を拾ってくるとき、
//                               当該記事のサイト名も一緒に拾うようにした
//     Version 1.4  14 Jun 2005  Bloglines で RSS フィード内に 1個しか記事
//                               がないとき、0x0A もしくは 0x0D が含まれる
//                               ときなど、記事題名、URL を取得するのに失敗
//                               するケース(既知のもののみ)に対処
//     Version 1.3  14 Jun 2005  Ver 1.2 で Bloglines の日本語モードにしか
//                               対応しなくなってしまっていた不具合を修正。
//                               英語モードでも動くことを確認。
//     Version 1.2  13 Jun 2005  (1) Bloglines で読んでいる記事をクリップす
//                                   るとき、違う記事のURL、題名を持ってき
//                                   てしまう可能性を極力減らした
//                               (2) Google の検索結果から、元記事をブック
//                                   マークできるようにしてみた
//                               (3) はてなRSS で読んでいる記事もそのまま
//                                   ブックマークできるようにしてみた
//                               (4) 実際にブックマークを実行する前に投稿内
//                                   容を確認するためのダイアログを出すよう
//                                   にした
//     Version 1.1   9 Jun 2005  Bloglines で読んでいる記事をそのままブック
//                               マークできるようにした
//     Version 1.0   6 Jun 2005  最初の版

obj = external.menuArguments;     // 右クリック時の引数のオブジェクトの参照
page_url   = obj.document.URL;    // ページのURL
title_txt  = obj.document.title;  // タイトル文字列
cite_range = obj.document.selection.createRange();
cite_txt   = cite_range.text;     // 引用文字列
cite_html  = cite_range.htmlText; // 引用文字列(html)
inn        = obj.document.body.innerHTML;

if ( obj.location.href && (obj.location.href != "") )
    page_url = obj.location.href; // 「はてなダイアリーキーワード」対策

// 注意: (1) はてなにログイン済みの状態で使うことを前提にしています。
//       (2) ブックマークしようとしている Web ページを誰もまだ登録していない
//           場合、「はてなブックマーク」では title の値を指定しても無視され
//           ます。
//           (はてなサーバ側で当該Webページを取得し、その Web ページの title
//            要素を取得し、初期値として採用する仕様のため)
//       (3) del.icio.us はログイン済みでなくても使えますが、本ブックマーク起
//           動時点でログイン済みでない場合は、漢字等が文字化けします。文字化
//           けを避けるために、あらかじめログインしておくことをおすすめします。

// ↓↓ あなたのアカウントに変更して、お使いください
del_userID = "tsupo";           // del.icio.us のアカウント
// ↑↑ あなたのアカウントに変更して、お使いください

hatenaIdForTipsjar = ""; // はてな投げ銭送信先ID
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);
                    //  if ( target2 == "" ) { /* {@@} 2005.07.15 追加 ↓ */
                    //      done = true;
                    //      break;
                    //  }                      /* {@@} 2005.07.15 追加 ↑ */
                        continue;
                    }
                    if ( (target2 != "") && (aim2.indexOf(target2) == -1) && (target2.indexOf(aim2) == -1) ) {
                        aim = aim.substring(e_summary+39,aim.length);
                        loc += (e_summary+39);
                    //  if ( target3 == "" ) { /* {@@} 2005.07.15 追加 ↓ */
                    //      done = true;
                    //      break;
                    //  }                      /* {@@} 2005.07.15 追加 ↑ */
                        continue;
                    }
                    if ( (target3 != "") && (aim2.indexOf(target3) == -1) && (target3.indexOf(aim2) == -1) ) {
                        aim = aim.substring(e_summary+39,aim.length);
                        loc += (e_summary+39);
                    //  if ( target4 == "" ) { /* {@@} 2005.07.15 追加 ↓ */
                    //      done = true;
                    //      break;
                    //  }                      /* {@@} 2005.07.15 追加 ↑ */
                        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 == "" ) { /* {@@} 2005.07.15 追加 ↓ */
                    //      done = true;
                    //      break;
                    //  }                      /* {@@} 2005.07.15 追加 ↑ */
                    }
                    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;
                        }
                    }
                }
            }
        }

        if ( page_url.match("http://www.bloglines.com/myblogs_display") ) {
            /* 上記の処理でうまく page_url や title_txt が拾えなかった場合  */
            /* (例えば、RSS Rolling の記事は、上記の処理で拾えるものと拾え  */
            /*  ないものがある)                                             */
            /*   注意: 最初からどんな場合も以下の処理を実行すればいいかと   */
            /*         いうとそういう訳でもなく、例えば、「人力検索はてな」 */
            /*         は以下の処理ではうまく拾えない一方、上記の処理では   */
            /*         ちゃんと拾えたりする                                 */
            loc = inn.indexOf(cite_txt);
            if ( loc > 0 ) {
                s = inn.substring(0,loc);
                loc2 = s.lastIndexOf("<h3><a title=");
                if ( loc2 > 0 ) {
                    s = s.substring(loc2+12,s.length);
                    loc3 = s.indexOf('href=\\"');
                    if ( loc3 > 0 )
                        page_url = s.substring(loc3+7,s.indexOf('\\" target='));
                    loc4 = s.indexOf("target=_blank>");
                    if ( loc4 > 0 )
                        title_txt = s.substring(loc4+14,s.indexOf("</a>"));
                }
            }
        }
    }
    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;
                }
            }
        }
    }
}

function hatenaIdAutoDiscovery()
{
    var ret = false;

    // まず、head 部分から探索
    var str  = obj.document.body.parentNode;
    var inn  = str.innerHTML;
    var idx1 = inn.indexOf("foaf:OnlineAccount");
    if ( idx1 == -1 ) {
        // head 部分に存在しない場合は body 部分を探索
        str  = obj.document.body;
        inn  = str.innerHTML;
        idx1 = inn.indexOf("foaf:OnlineAccount");
    }

    if ( idx1 > 0 ) {
        if ( inn.indexOf('<foaf:accountServiceHomepage rdf:resource="http://www.hatena.ne.jp/" />') > 0 ) {
            idx2 = inn.indexOf('foaf:accountName="');
            if ( idx2 > 0 ) {
                hatenaIdForTipsjar = inn.substring(idx2+18,inn.indexOf('</foaf:OnlineAccount>'));
                hatenaIdForTipsjar = hatenaIdForTipsjar.substring(0, hatenaIdForTipsjar.indexOf('"'));
                ret = true;
            }
        }
    }

    return ( ret );
}

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

// URL 末尾の ?ref=rss のようなトラッキング用文字列を取り除く
rssIdx = page_url.indexOf("?ref=rss"); // ?ref=rssall のようなパターンもあり
if ( rssIdx < 0 )
    rssIdx = page_url.indexOf("?ref=atom");
if ( rssIdx < 0 )
    rssIdx = page_url.indexOf("?from=rss");
if ( rssIdx < 0 )
    rssIdx = page_url.indexOf("?from=RSS");
if ( rssIdx < 0 )
    rssIdx = page_url.indexOf("?from=atom");
if ( rssIdx < 0 )
    rssIdx = page_url.indexOf("?fr=RSS");
if ( rssIdx < 0 )
    rssIdx = page_url.indexOf("&f=rss");
if ( rssIdx < 0 )
    rssIdx = page_url.indexOf("&f=atom");
if ( rssIdx >= 0 )
    page_url = page_url.substring(0,rssIdx);

ok = confirm('URL: '+page_url+'\nタイトル: '+title_txt+'\n引用: '+cite_txt);

if ( ok ) {
    if ( cite_txt != "" ) {
        // はてなID auto-discovery (投げ銭可能かどうかチェック)
        isTipsjarOK = hatenaIdAutoDiscovery();
        asin = "";
        if ( page_url.match("/asin/") || page_url.match("/ASIN/") || page_url.match("/gp/product/") ) {
            asinIdx = page_url.indexOf("/asin/");
            if ( asinIdx < 0 )
                asinIdx = page_url.indexOf("/ASIN/");
            if ( asinIdx < 0 )
                asinIdx = page_url.indexOf("/gp/product/") + 6; // スポーツストアの場合 [cite_txt != "" のときだけの特別サービス、ということで、どうかひとつ]
            if ( asinIdx >= 0 ) {
                asinIdx += 6;
                len = page_url.length;
                if ( len >= asinIdx + 11 )
                    len = asinIdx + 11;
                asin = page_url.substring(asinIdx,len);
                if ( asin.charAt(asin.length - 1) == '/' )
                    asin = asin.substring(0,asin.length - 1);
            }
        }

        // マウスで選択中の文字列があれば、extended に入れる
        newWin = window.open('http://b.hatena.ne.jp/add?mode=confirm&is_bm=1&title='+escape(title_txt)+'&url='+escape(page_url)+'&comment='+escape(cite_txt), '_blank', 'width=520,height=600,resizable=1,scrollbars=1');
        window.open('http://del.icio.us/' + del_userID + '?v=2&url=' + encodeURIComponent(page_url) + '&title=' + encodeURIComponent(title_txt) + '&extended=' + encodeURIComponent(cite_txt));

        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.document.open();

        newWin.document.write("<html>\n<head>\n<title>はてなブックマーク - ソーシャルブックマーク</title>\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('<sc' + 'ript type="text/javascript" src="http://b.hatena.ne.jp/js/comment_counter.js"></sc' + 'ript>\n');
        newWin.document.write('<link rel="stylesheet" type="text/css" href="http://b.hatena.ne.jp/style">\n');
        newWin.document.write('<style type="text/css">\n#body {\n  margin-left: 0px;\n}\n\n.info td {\n  font-size: 80%;\n}\n\n');
        newWin.document.write('div.note {\n  margin-left: 10px;\n  margin-top:  20px;\n}\n\n');
        newWin.document.write('div.info p {\n  font-size: 90%;\n}\n\ndiv.info p.addurl-footer {\n  font-size: 100%;\n}\n');
        newWin.document.write('</style>\n');
        newWin.document.write('</head>\n<body>\n');

        newWin.document.write('<div id="banner"><h1><a href="http://www.hatena.ne.jp/" target="_blank"><img src="http://b.hatena.ne.jp/images/hatena_de.gif" width="104" height="40" alt="Hatena"></a>');
        newWin.document.write('<a href="http://b.hatena.ne.jp/" target="_blank"><img src="http://b.hatena.ne.jp/images/Bookmarkde.gif" width="118" height="40" alt="Bookmark"></a>');
        newWin.document.write('<img src="http://b.hatena.ne.jp/images/betade.gif" width="42" height="40" alt="beta" title="beta">');
        newWin.document.write('<img border="0" src="http://b.hatena.ne.jp/images/tri_de.gif" width="15" height="40" usemap="#trimap" alt="tri"></h1>');
        newWin.document.write('<a href="http://www.hatena.ne.jp/"><img src="http://b.hatena.ne.jp/images/hatenade.gif" class="logo" alt="はてな" title="はてな"></a></div>\n');
        newWin.document.write('<map name="trimap">\n');
        newWin.document.write('<area shape="rect" coords="1,10,15,25" href="http://a.hatena.ne.jp/" alt="はてなアンテナ" title="はてなアンテナ">\n');
        newWin.document.write('<area shape="rect" coords="1,25,15,40" href="http://d.hatena.ne.jp/" alt="はてなダイアリー" title="はてなダイアリー">\n');
        newWin.document.write('</map>\n');

        newWin.document.write('<div id="container">\n');
        newWin.document.write('<div id="body">\n');
        newWin.document.write('<h2>ブックマークの確認</h2>\n');
        newWin.document.write('<form action="http://b.hatena.ne.jp/add" method="POST" name="add" id="edit_form" style="margin:0">\n');
        newWin.document.write('<input type="hidden" name="mode" value="enter">\n');
        newWin.document.write('<input type="hidden" name="eid" value="">\n');
        newWin.document.write('<input type="hidden" name="url" value="' + page_url + '">\n');
        newWin.document.write('<input type="hidden" name="rkm" value="' + rkm + '">\n');
        newWin.document.write('<input type="hidden" name="is_bm" value="1">\n');
        newWin.document.write('<div class="info">\n<table>\n<tr>\n');
        newWin.document.write('<td class="label" nowrap>URL</td>\n<td class="addurl">\n');
        newWin.document.write('<a href="' + page_url + '" target="_blank">' + page_url + '</a>\n');
        newWin.document.write('</td>\n</tr><tr>\n<td class="label" nowrap>タイトル</td>\n<td>\n');
        newWin.document.write('<input type="text" name="title" value="' + title_txt + '" size="50" />\n');
        newWin.document.write('</td>\n</tr>\n<tr>\n<td class="label" nowrap>コメント<br><span class="note">(省略可)</span></td>\n<td>\n');
        newWin.document.write('<input type="text" name="comment" id="comment" value="' + cite_txt + '" size="50" onKeyUp="countBytes()" />\n');
        newWin.document.write('<span id="comment_count"></span>\n<div id="candidates_list"></div>\n</td>\n</table>\n');
        newWin.document.write('</div>\n');

        if ( isTipsjarOK ) {
            newWin.document.write('<!-- ポイント送信 -->\n');
            newWin.document.write('<input type="hidden" name="hatenaid" value="' + hatenaIdForTipsjar + '">\n');
            newWin.document.write('<p><input type="checkbox" name="tipjar" value="1" id="tipjar"> <label for="tipjar">このエントリーの作者にポイントを送信する</label></p>\n');
        }
        else if ( asin != "" ) {
            newWin.document.write('<input type="hidden" name="asin" value="' + asin + '">\n');
            newWin.document.write('<p><input type="checkbox" name="addasin" value="1" checked="checked">この商品をコレクションに加える</p>\n');
        }

        newWin.document.write('<input type="submit" name="commit" value="追加する">\n');
        newWin.document.write('<input type="submit" name="go_bm" value="追加して確認">\n');
        newWin.document.write('<div id="tags_list"></div>\n<div id="othertags_list"></div>\n<div id="keywords_list"></div>\n');
        newWin.document.write('</form>\n');
        newWin.document.write('<div class="note" style="padding-bottom: 1em;">※コメント欄で"[hoge]..."と書くとタグが利用できます。→<a href="/help#tag" target="_blank">詳しい説明</a></div>\n');
        newWin.document.write('</div>\n</div>\n');
        newWin.document.write('</body>\n</html>\n');

        newWin.document.close();
        newWin.document.focus();
    }
    else {
        window.open('http://b.hatena.ne.jp/add?mode=confirm&is_bm=1&title='+escape(title_txt)+'&url='+escape(page_url), '_blank', 'width=520,height=600,resizable=1,scrollbars=1');
        window.open('http://del.icio.us/' + del_userID + '?v=2&url=' + encodeURIComponent(page_url) + '&title=' + encodeURIComponent(title_txt));
    }
}
</script>

余談

bookey の方でも「コレクション」に対応しようと思ったんですが、「コレクション」の方は、今のところ Atom Publishing Protocol では操作できないようです。とりあえず、「コレクション」も Atom Publishing Protocol (Atom API) に対応して欲しいという要望を出しておきました。

関連記事

投稿者: tsupo 2006.04.04 午後 06:39 | 固定リンク | このエントリーをはてなブックマークに追加 | このエントリを del.icio.us に登録 このエントリの del.icio.us での登録状況 | このエントリを Buzzurl に追加このエントリの Buzzurl での登録状況 | このエントリをlivedoorクリップに登録 このエントリのlivedoorクリップでの登録状況 このエントリをlivedoorクリップに登録している人の数 | 酢鶏巡回中

楽天市場


品揃え豊富で安い!NTT-X Store


アマゾンわくわく探検隊

トラックバック

この記事のトラックバックURL:

この記事へのトラックバック一覧です: 右クリックではてなブックマーク、ついでにdel.icio.us (はてなブックマーク「コレクション」対応版):

» RSS で全文配信したからといって…… (ついでに bookey のデモを作ってみたよ) from 観測気球
RSS で全文配信したからといって、ブックマークされにくくなる、なんてことはないと思います。むしろ、全文流すことでブックマークされやすくなるんじゃないかと予想しています。 続きを読む

受信: 2006.04.20 午前 10:23

コメント

ワード

ニッセン

fujisan.co.jp

楽天市場