Created
June 2, 2009 05:41
-
-
Save Yasushi/122082 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
CmdUtils.CreateCommand({ | |
names: ["hatena bookmark comment", "hateb comment"], | |
icon: "http://b.hatena.ne.jp/favicon.ico", | |
author: {name: "Yasushi Abe", email: "yasushi.abe@gmail.com"}, | |
preview: function(pblock, args) { | |
if (!this._url()) { | |
pblock.innerHTML="show hatena bookmark comments."; | |
return; | |
} | |
pblock.innerHTML="Loading comments..."; | |
CmdUtils.previewAjax(pblock, { | |
url: "http://b.hatena.ne.jp/entry/rss/" + this._url(), | |
dataType: "xml", | |
error: function error(data) { | |
pblock.innerHTML = "error. " + data.status + " " + data.statusText; | |
}, | |
success: function commentPreview(data) { | |
if (!data) | |
pblock.innerHTML = "Error parsing results."; | |
else { | |
var users = 0, comments = [] | |
let desc = jQuery(data).find('description'); | |
desc.each(function eachDesc(i) { | |
if (i > 0 && this.textContent){ | |
comments.push({name: $('title',this.parentNode).get(0).textContent||"", comment: this.textContent||""}); | |
} | |
}); | |
if (comments.length) | |
pblock.innerHTML = CmdUtils.renderTemplate("<span style='color: #e66'>${users} users</span><br />{for c in comments}<div style='margin: 10px .5em 10px 1em;'><span style='color: #88d'>${c.name}</span> ${c.comment}</div>{/for}", {users:desc.size(), comments:comments}); | |
else | |
pblock.innerHTML = "No comments."; | |
} | |
}, | |
}); | |
}, | |
execute: function(input) { | |
if (this._url()) Utils.openUrlInBrowser('http://b.hatena.ne.jp/entry/' +this._url()); | |
}, | |
_url: function() { | |
var url = CmdUtils.getWindow().location.href.replace(/#/,'%23'); | |
if (!new RegExp("^https?://").test(url)) { | |
return; | |
} | |
return url; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment