-
-
Save a2chub/22182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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