From 251cf6fd9137ad59ddfc4726ac6750e40529607d Mon Sep 17 00:00:00 2001 From: teramako Date: Tue, 28 Sep 2010 13:17:22 +0000 Subject: 画像表示の仕組み変更と対応ページ追加 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@38526 d0d07461-0603-4401-acd4-de1884942a52 --- twittperator/twlist-win.tw | 169 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 137 insertions(+), 32 deletions(-) diff --git a/twittperator/twlist-win.tw b/twittperator/twlist-win.tw index 0a4154a..7128fad 100644 --- a/twittperator/twlist-win.tw +++ b/twittperator/twlist-win.tw @@ -44,6 +44,7 @@ let winXML = <> tabBox = $("twlist-tabbox"); cmdBox = $("twlist-command"); - liberator.plugins.twittperator.Tweets.slice(0,twlist.maxRows).reverse().forEach(function(it) add(it)); + liberator.plugins.twittperator.Tweets.slice(0,twlist.maxRows).reverse().forEach(add); if (twlist.trackWords){ if (twlist.twlistTrack){ TrackTabs.init(twlist.twlistTrack); @@ -621,23 +622,98 @@ function onUnload () { plugins.twittperator.TrackingStream.removeListener(listener.trackStream); } -function getMedia (uri) { - if (/\.gif$|\.jpe?g$|\.pi?ng$/.test(uri.path)) - return ["image", uri.spec]; - switch (uri.host) { - case "twitpic.com": - return ["image", "http://twitpic.com/show/thumb" + uri.path + ".jpg"]; - case "movapic.com": - return ["image", "http://image.movapic.com/pic/m_" + uri.path.substr(uri.path.lastIndexOf("/")+1) + ".jpeg"]; - case "gyazo.com": - return ["image", uri.spec]; - case "twittgoo.com": - let elm = util.httpGet(uri.spec + "/?format=atom").responseXML.getElementsByTagName("icon")[0]; - return ["image", elm.textContent]; - case "www.flickr.com": - case "f.hatena.ne.jp": - default: - return []; +function getMedia (uri, elm, callback) { + var media = {}; + if (/\.gif$|\.jpe?g$|\.pi?ng$/.test(uri.path)){ + media = { image: uri.spec, anchor: uri.spec }; + } else { + switch (uri.host) { + case "twitpic.com": + media = { + image: "http://twitpic.com/show/thumb" + uri.path + ".jpg", + anchor: uri.spec + }; + break; + case "movapic.com": + media = { + image: "http://image.movapic.com/pic/m_" + uri.path.substr(uri.path.lastIndexOf("/")+1) + ".jpeg", + anchor: uri.spec + }; + break; + case "gyazo.com": + media = { + image: uri.spec, + anchor: uri.spec + }; + break; + case "twittgoo.com": + util.httpGet(uri.spec + "/?format=atom", function(xhr){ + let elm = xhr.responseXML.getElementsByTagName("icon")[0]; + callback(elm, { image: elm.textContent, anchor: uri.spec }); + }); + return; + case "www.youtube.com": { + let query = uri.path.substr(1).split("?")[1]; + if (!query) break; + let hash = query.split("&").filter(function(param) param.indexOf("v=")==0)[0]; + if (!hash) break; + media = { + image: "http://i.ytimg.com/vi/" + hash + "/1.jpg", + anchor: uri.spec + }; + break; + } + case "f.hatena.ne.jp": { + let [, userid, date] = uri.path.split("/"); + media = { + image: ["http://img.f.hatena.ne.jp/images/fotolife/", + userid.charAt(0), "/", userid, "/", date.substr(0, 8), + "/", date, "_m.jpg"].join(""), + anchor: uri.spec + }; + break; + } + case "photomemo.jp": { + let [, user, num] = uri.path.split("/"); + util.httpGet(uri.prePath + "/" + user + "/rss.xml", function(xhr){ + let items = xhr.responseXML.querySelectorAll("item"); + for (let i=0, item; item = items[i]; i++){ + if (item.querySelector("link").textContent == uri.spec) { + callback(elm, { image: item.querySelector("content").getAttribute("url"), anchor: uri.spec }); + return; + } + } + }); + return; + } + case "www.flickr.com": { + let [,,user, id, id2, setId] = uri.path.split("/"); + let imgReg; + if (id == "sets" && id2) { + imgReg = /; while((m=reg.exec(str))){ buf = str.substring(i, m.index); if (buf) x.appendChild(buf); - let class = "twlist-link", href = ""; + let classValue = "twlist-link", href = ""; switch (m[0].charAt(0)){ case "@": - class += " twlist-user"; + classValue += " twlist-user"; href = "http://twitter.com/" + m[0].substr(1); break; case "#": - class += " twlist-hash"; + classValue += " twlist-hash"; href = "http://twitter.com/search?q=%23" + m[0].substr(1); break; default: - class += " twlist-url"; + classValue += " twlist-url"; href = m[0]; } - x.appendChild({m[0]}); i=reg.lastIndex; } @@ -782,6 +885,8 @@ function onKeyDown(event){ if (/^@\w+#\d+$/.test(txt.trim())) return; liberator.execute('tw ' + txt, null, true); + event.target.value = ""; + event.target.blur(); } break; } -- cgit v1.2.3