Skip to content

Instantly share code, notes, and snippets.

@a2chub
Created November 4, 2008 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2chub/22182 to your computer and use it in GitHub Desktop.
Save a2chub/22182 to your computer and use it in GitHub Desktop.
// Copy right 2008 Shumpei Shiraishi (shiraishi at ayuta.co.jp)
CmdUtils.CreateCommand({
name: "hotentry",
takes: {"エントリの番号を入力": noun_arb_text},
preview: function(prev, index) {
var $ = jQuery;
var feedUrl = "http://b.hatena.ne.jp/hotentry/diary/rss";
var self = this;
$.get(feedUrl,function(feed) {
var entries = [];
var listHtml = "<ol>";
$("item", feed).slice(0, 10).each(function(index, item) {
var text = $("title", item).text();
var link = $("link", item).text();
entries.push({text: text, link: link});
listHtml +=
"<li>" +
"<a href='" + link + "'>" + text + "</a>" +
"</li>";
});
listHtml += "</ol>";
$(prev).html(listHtml);
globals.entries = entries;
}, "xml");
},
execute: function(index) {
var self = this;
try {
index = parseInt(index.text, 10);
} catch (e) {
return;
}
var task = function() {
var entries = globals.entries;
if (!entries || entries.length == 0) {
window.setTimeout(task, 500);
return;
}
if (index > entries.length) {
return;
}
CmdUtils.getWindowInsecure().open(entries[index-1].link);
};
task();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment