Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created June 15, 2009 04:16
Show Gist options
  • Save Yasushi/129945 to your computer and use it in GitHub Desktop.
Save Yasushi/129945 to your computer and use it in GitHub Desktop.
/**
* Favotter Viewer.
* Respect
* http://jsgt.org/mt/01/
* http://d.hatena.ne.jp/murky-satyr/
*
* TODO:HTTP 503のときに起こってる悲しい事態を何とかする。
*/
+function($j, urls){
CmdUtils.CreateCommand({
name: "favotter",
description: "Favotter viewer.",
help: "favotter {screen_name}",
icon: "http://favotter.matope.com/favicon.ico",
takes: {user_name: noun_arb_text},
preview: function(pb, {text}){
pb.innerHTML = this._logo;
var p = this._sname(text);
if (p && p != ''){
pb.innerHTML = "Loading...";
// this._render.byRss(pb, p); //RSS
this._render.byHtml(pb, p); //HTML
}
},
previewDelay: 333,
execute: function({text}){
Utils.openUrlInBrowser(urls.html + this._uname(text));
},
_logo: <><![CDATA[
<p><a
href='http://favotter.matope.com/'><img
src='http://favotter.matope.com/favotterR.png'
style='width:100px;border: none;'></a></p>
]]></>,
_sname: function(inp){
if(inp){
return encodeURI(jQuery.trim(inp));
}else{
var ptn = /http:\/\/twitter\.com\/(\w*)[\/.+]?/;
var loc = CmdUtils.getDocument().location.href;
return ptn.test(loc) ? encodeURI(ptn.exec(loc)[1]) : "";
}
},
_render: {
byHtml: function(pb, param){
Utils.parseRemoteDocument(
urls.html+param, null,
function(doc){
$j(pb).empty();
$j(pb).append($j(doc).find("div.description"));
$j(doc).find(".info a").each(function(){
// 相対パスをフルパスに
var href = $j(this).attr("href");
if (href.indexOf("http") == -1){
$j(this).attr("href", urls.def + href);
}
});
$j(doc).find(".hentry").each(function(){
$j(pb).append("<hr />")
.append($j(this).find(".status_text")) // ふぁぼられstat
.append($j(this) // ふぁぼられstatの情報
.find(".info a").end()
.find(".info").css({"text-align": "right"})
);
});
// 画像のボーダー削除
$j(pb).find("img").css({"border": "none", "width": "16px"});
},
function(){pb.innerHTML = 'AjaxError'.italics()}
);
},
byRss: function(pb, param){
CmdUtils.previewAjax(pb, {
url: urls.rss, data: {user: param}, async: false,
success: function(rss){
$j(pb).empty();
$j(rss).find("description").each(function(){
$j(pb).append($j(this).text());
});
$j(pb).css({"color": "#70EE0A", "background-color": "#999"});
},
error: function(){pb.innerHTML = 'AjaxError'.italics()}
});
}
},
author: "powchin".link("http://friendfeed.com/powchin"),
licence: 'MIT',
});
}(jQuery, {
def: "http://favotter.matope.com/",
html: "http://favotter.matope.com/user.php?user=",
rss: "http://favotter.matope.com/userrss.php"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment