【連続VersionUp】Twitterで画像をサムネイル表示するスクリプト

G.W中に生活に変化があり、しばらくネットも使えなかったのですが、今日、頼んでいたTry WiMAXのルータが届いたのでようやくPCでネットができます。

USENスピードテストだと、下り1.5〜4Mbpsで数値的には今イチですが、体感では全然問題なさげに感じます。
うーん、WiMAXだけで大丈夫かなぁ・・・。



と、余談はさておき、ryoさんから要望をいただいたので、バージョンアップしました。

http://が省かれていたり、短縮URLになっている画像リンクもサムネイル表示するようになりました。

ついでに、偶然タイムラインにあったので「フォト蔵」のリンクにも対応しました。


使い方は前々回の記事を参照してください。

最新のスクリプトは下記になります。
(はやくダウンロードできるようにしなくては、、、)



// ==UserScript==
// @name Tweet Image Viewer
// @namespace
// @description
// @include http://twitter.com/*
// @auther ugon105
// v0.1 : 2010.04.19 : First Release
// v1.0 : 2010.10.03 : version 1.0 Release
// v1.1 : 2010.11.17 : support for movapic, twipple
// v1.2 : 2011.04.28 : support for instagram
// v1.3 : 2011.05.10 : support for photozou. and support shortening URL, and fixed several bug.

var targetClass = undefined;
function insertImg() {
var anchors = document.getElementsByClassName(targetClass),
i = 0,
len = anchors.length,
href,
thmbUrl,
pid,
img,
getLastWord = function(url) {
var vals = url.split("/"),
l = vals.length,
w;

for (; l > 0; l -=1) {
w = vals[l - 1];
if (w) {
return w;
}
}
return "";
};

for (; i < len; i += 1) {
if (anchors[i].className.indexOf("preview-done") > 0) {
continue;
}

href = anchors[i].getAttribute('data-expanded-url');
if (!href) {
href = anchors[i].href;
}
thmbUrl = undefined;
// twitpic
if (href.indexOf("http://twitpic.com/") == 0) {
thmbUrl = "http://twitpic.com/show/thumb/" + getLastWord(href);
}
// yfrog
else if (href.indexOf("http://yfrog.com") == 0) {
thmbUrl = href + ".th.jpg";
}
// plixi
else if (href.indexOf("http://plixi.com/p/") == 0) {
thmbUrl = "http://api.plixi.com/api/TPAPI.svc/imagefromurl?size=small&url=" + href;
}
// movapic
else if (href.indexOf("http://movapic.com/") == 0) {
thmbUrl = "http://image.movapic.com/pic/s_" + getLastWord(href) + ".jpeg";
}
// twipple
else if (href.indexOf("http://p.twipple.jp/") == 0) {
pid = getLastWord(href);
thmbUrl = "http://p.twipple.jp/data/"
+ pid.substr(0,1) + "/"
+ pid.substr(1,1) + "/"
+ pid.substr(2,1) + "/"
+ pid.substr(3,1) + "/"
+ pid.substr(4,1) + "_s.jpg";

}
// instagram
else if (href.indexOf("http://instagr.am/p/") == 0) {
thmbUrl = href + "media/?size=t";
}
// photozou
else if (href.indexOf("http://photozou.jp/photo/") == 0) {
thmbUrl = "http://photozou.jp/p/thumb/" + getLastWord(href);
}

if (thmbUrl) {
img = document.createElement("img");
img.src = thmbUrl;
with (img.style) {
border = "1px solid #ccc";
padding = "5px";
display = "block";
marginTop = "10px";
}
anchors[i].appendChild(img);
anchors[i].className += " preview-done";
}
}
}

if (document.getElementById("timeline")) {
targetClass = "tweet-url web";
} else if (document.getElementById("doc") && document.getElementById("top-stuff")) {
targetClass = "twitter-timeline-link";
}

if (targetClass) {
insertImg(targetClass);
setInterval(insertImg, 5000);
}