Blackbird bookmarklet mod

  • /*
     * @title Blackbird bookmarklet mod
     * @description Blackbird bookmarkletをちょっといじった
     * @include https?:\/\/twitter.com\/(#!\/|)(.{1,15})\/status(es)?\/([0-9]{3,20})
     * @license not sure
     * @thanks http://publitweet.com/blackbird/bookmarklet.js
     * @thanks http://l-w-i.net/m/20081202_01.txt
     * @thanks http://micelle.org/trash/fdate/
     */
    var PUBLITWEET_INTERFACE_LOADED = !1;
    function publitweet_blackbird_close() {
      id = "publitweet_bookmarklet";
      PUBLITWEET_INTERFACE_LOADED = !1;
      jQuery("#" + id).remove()
    }
    function showItem(a) {
      try {
        var b = document.getElementById(a);
        if(b) {
          b.style.display = ""
        }
      }catch(g) {
      }
    }
    (function() {
      u = document.location.href;
      if(matches = u.match(/https?:\/\/twitter.com\/(#!\/|)(.{1,15})\/status(es)?\/([0-9]{3,20})/i)) {
        publitweet_blackbird_getCode(matches[4])
      }else {
        if(m2 = u.match(/^https?:\/\/twitter.com(\/.*)?/i)) {
          if(console.info("Starting publitweet"), 0 == jQuery(".publitweet_blackbird_getEmbed").size()) {
            var a = function(a, b) {
              for(var f = 0, h = b.length;f < h;f++) {
                if(b[f] == a) {
                  return!0
                }
              }
              return!1
            }, b = [];
            jQuery(".stream-tweet, .permalink-tweet").live("hover", function() {
              var g = jQuery(this).find(".tweet-actions");
              if(g) {
                var d = g.siblings(".tweet-timestamp").attr("href").replace("/#!", "http://twitter.com"), f = $(this).hasClass("permalink-tweet") ? "permalink" : "stream";
                if(!a(f + ":" + d, b)) {
                  var h = d.match(/https?:\/\/twitter.com\/(.{1,15})\/status(es)?\/([0-9]{3,20})/i)[3];
                  b.push(f + ":" + d);
                  console.info("publitweet_blackbird_ id: " + h);
                  d = jQuery('&nbsp; <a class="publitweet_blackbird_getEmbed" href="javascript:void();" style="display:inline-table;height:16px;padding-left:18px;">[embed tweet]</a>');
                  g.append(d);
                  d.click(function() {
                    publitweet_blackbird_getCode(h)
                  })
                }
              }
            })
          }
        }else {
          alert("You have to be on a twitter.com page to execute this bookmarklet")
        }
      }
    })();
    function publitweet_writeInterface() {
      if(!PUBLITWEET_INTERFACE_LOADED) {
        PUBLITWEET_INTERFACE_LOADED = !0;
        var a = document.createElement("div");
        a.id = "publitweet_bookmarklet";
        t = Math.round((jQuery(window).height() - 400) / 2);
        l = Math.round(jQuery(window).width() / 2 - 250);
        a.innerHTML = '<div id=publitweet_bookmarklet_table style="background:#E9EAEE;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;-moz-box-shadow:1px 2px 6px rgba(0, 0, 0, 0.5);box-shadow: 1px 2px 6px rgba(0,0,0, 0.5);-webkit-box-shadow: 1px 2px 6px rgba(0,0,0, 0.5);' + ("padding:9px 10px;border:border:2px solid #FFFFFF; position:fixed; _position:absolute;top:" + t + "px;left:" + l + "px;") + "width:500px;height: 400px;z-index:10000000;margin:0;padding:0;background:'#E9EAEE';\"><div style='padding:10px;width:430px;margin:0 auto;'><h2 style='text-align:left;margin-top:10px;color:#393939 !important;'>Publitweet blackbird</h3><h3 style='text-align:left;margin-top:10px;color:#393939 !important;'>HTML code:</h3><textarea id=EmbedCode style='margin:10px 0px;background:none repeat scroll 0 0 #FAFAFC;border:1px solid #A3A3A3;color:#2F2F2F;font:10px/15px Monaco,monospace;height:240px;outline:medium none;overflow:hidden;padding:9px 0px;width:430px;'>Loading..</textarea><center><a href='javascript:publitweet_blackbird_close();' style='width:100%; text-align: middle; color: #393939; font-family: Arial;'><b>[close (^esc)]</b></a></center></div></div>";
        jQuery(document).keyup(function(a) {
          27 == a.keyCode && publitweet_blackbird_close()
        });
        jQuery("#EmbedCode").focus(function() {
          jQuery(this).select()
        });
        document.body.insertBefore(a, document.body.firstChild)
      }
    }
    function publitweet_blackbird_getCode(a) {
      publitweet_writeInterface();
      e = document.getElementById("EmbedCode");
      e.value = "Loading...";
      api_call = "http://api.twitter.com/1/statuses/show/" + a + ".json?callback=publitweet_blackbird";
      _my_script = document.createElement("SCRIPT");
      _my_script.type = "text/javascript";
      _my_script.src = api_call;
      document.getElementsByTagName("head")[0].appendChild(_my_script)
    }
    function publitweet_blackbird(a) {
      tweet_id = a.id_str;
      screen_name = a.user.screen_name;
      name = a.user.name;
      background_url = a.user.profile_background_image_url;
      avatar = a.user.profile_image_url;
      source = a.source;
      c = a.created_at.split(" ");
      var b = new Date(c[1] + " " + c[2] + ", " + c[5] + " " + c[3]);
      b.setHours(b.getHours() + 9);
      myYear = b.getFullYear();
      myMonth = b.getMonth() + 1;
      myDate = b.getDate();
      myHour = b.getHours();
      myMin = b.getMinutes();
      mySec = b.getSeconds();
      10 > myMonth && (myMonth = "0" + myMonth);
      10 > myDate && (myDate = "0" + myDate);
      10 > myHour && (myHour = "0" + myHour);
      10 > myMin && (myMin = "0" + myMin);
      10 > mySec && (mySec = "0" + mySec);
      timestamp = myYear + "-" + myMonth + "-" + myDate + "T" + myHour + ":" + myMin + ":" + mySec + "+09:00";
      content = a.text.replace(/(http:\/\/\S+)/g, "<a href='$1' rel=nofollow>$1</a>");
      profile_background_color = "#" + a.user.profile_background_color;
      content = content.replace(/#([a-z0-9]*)/ig, '<a href="http://twitter.com/search?q=%23$1" title="#$1" class="tweet-url hashtag" rel=nofollow>#$1</a>');
      content = content.replace(/@([a-z0-9_-]{1,15})/ig, '@<a class="tweet-url username" href="http://twitter.com/$1" rel=nofollow>$1</a>');
      EmbedCode = "<\!-- http://twitter.com/" + screen_name + "/status/" + tweet_id + " --\>\n";
      EmbedCode += "<style type='text/css'>.bbpBox" + tweet_id + "{background:url(" + background_url + ") " + profile_background_color + ";padding:20px}p.bbpTweet{-moz-border-radius:5px;-webkit-border-radius:5px;background:#fff;color:#000;font-size:18px!important;line-height:22px;margin:0;min-height:48px;padding:10px 12px 10px 12px}p.bbpTweet a:hover{text-decoration:underline}p.bbpTweet span.metadata{border-top:1px solid #e6e6e6;border-top:1px solid #fff;clear:both;display:block;height:40px;margin-top:8px;padding-top:12px;width:100%}p.bbpTweet span.metadata span.author{line-height:19px}p.bbpTweet span.metadata span.author img{float:left;height:38px;margin:0 7px 0 0;width:38px}p.bbpTweet span.timestamp{display:block;font-size:12px}</style>";
      EmbedCode += "<div class=bbpBox" + tweet_id + "><p class=bbpTweet>" + content + "<span class=timestamp><a title='" + timestamp + "' href='http://twitter.com/" + screen_name + "/status/" + tweet_id + "'>" + timestamp + "</a> via " + source + "<a href='http://twitter.com/intent/favorite?tweet_id=" + tweet_id + "'><img src='http://si0.twimg.com/images/dev/cms/intents/icons/favorite.png'/> Favorite</a> <a href='http://twitter.com/intent/retweet?tweet_id=" + tweet_id + "'><img src='http://si0.twimg.com/images/dev/cms/intents/icons/retweet.png'/> Retweet</a> <a href='http://twitter.com/intent/tweet?in_reply_to=" + 
      tweet_id + "'><img src='http://si0.twimg.com/images/dev/cms/intents/icons/reply.png'/> Reply</a></span><span class=metadata><span class=author><a href='http://twitter.com/" + screen_name + "'><img src='" + avatar + "'/></a><strong><a href='http://twitter.com/" + screen_name + "'>" + name + "</a></strong><br/>" + screen_name + "</span></span></p></div>\n<\!-- end of tweet --\>";
      e = jQuery("#EmbedCode");
      e.val(EmbedCode);
      e.focus();
      e.select()
    }
    ;
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2011/12/12 12:05:04 - 2011-12-12