Hatena bookmarklet

  • /*
     * @title Hatena bookmarklet
     * @description 旧はてなブックマークレットのcanonical URL対応版
     * @include http://*
     * @license MIT License
     * @require 
     */
    function absolutePath(path){
      var e = document.createElement('div');
      e.innerHTML = '<a href="' + path + '" />';
      return e.firstChild.href;
    }
    function getElementsByAttr(tag, attr, value){
            var el = document.getElementsByTagName(tag);
            for(var i=0, len=el.length; i<len; i++){
                    if(el[i].getAttribute(attr) == value){
                            return el[i];
                    }
            }
            return false;
    }
    var href;
    var canonical = getElementsByAttr("link" ,"rel" ,"canonical");
    if(canonical){
        href = absolutePath(canonical.href);
    }else{
        href = location.href;
    }
    location.href='http://b.hatena.ne.jp/add?mode=confirm&title='+escape(document.title)+'&url='+escape(href);
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2010/06/11 02:10:20 - 2010-06-11
  2. 2010/06/11 02:05:42 - 2010-06-11
  3. 2010/06/11 02:03:07 - 2010-06-11
  4. 2010/06/11 02:01:48 - 2010-06-11