Created
August 28, 2008 08:18
-
-
Save darashi/7676 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
function SBM() {} | |
SBM.prototype = { | |
initialize : function(pblock, url) { | |
this._pblock = pblock; | |
this._url = url; | |
this._div_id = this._id + "-results"; | |
}, | |
displayResult : function(result) { | |
jQuery("#"+this._div_id, this._pblock)[0].innerHTML = result ? | |
result : "no bookmarks with comment"; | |
}, | |
html : function() { | |
return "<b><a href=\""+this.bookmarkUrl()+"\">"+this._serviceName+"</a></b><div id=\""+this._div_id+"\">feching...</div>"; | |
} | |
} | |
function HatenaBookmark() { | |
this.initialize.apply(this, arguments); | |
} | |
HatenaBookmark.prototype = new SBM(); | |
HatenaBookmark.prototype._id = "hatena-bookmark"; | |
HatenaBookmark.prototype._serviceName = "Hatena bookmark"; | |
HatenaBookmark.prototype.bookmarkUrl = function() { | |
return "http://b.hatena.ne.jp/entry/"+this._url; | |
} | |
HatenaBookmark.prototype.fetch = function() { | |
var template = "(${count} bookmarks)<div><ul>{for bookmark in bookmarks}{if bookmark.comment}<li><a href=\"http://b.hatena.ne.jp/${bookmark.user}\">${bookmark.user}</a>: ${bookmark.comment}</li>{/if}{/for}</ul></div>"; | |
var jsonUrl = "http://b.hatena.ne.jp/entry/json/"+this._url; | |
var t = this; | |
jQuery.get( jsonUrl, {}, function(data) { | |
if(data) { | |
CmdUtils.log(data); | |
t.displayResult(CmdUtils.renderTemplate(template, data)); | |
} else { | |
t.displayResult(); | |
} | |
}, "json"); | |
} | |
function LivedoorClip() { | |
this.initialize.apply(this, arguments); | |
} | |
LivedoorClip.prototype = new SBM(); | |
LivedoorClip.prototype._id = "livedoor-clip"; | |
LivedoorClip.prototype._serviceName = "Livedoor clip"; | |
LivedoorClip.prototype.bookmarkUrl = function() { | |
return "http://clip.livedoor.com/page/"+this._url; | |
} | |
LivedoorClip.prototype.fetch = function() { | |
var template = "<div><ul>{for comment in Comments}<li><a href=\"http://clip.livedoor.com/clips/${comment.livedoor_id}\">${comment.livedoor_id}</a>: ${comment.notes}</li>{/for}</ul></div>"; | |
var jsonUrl = "http://api.clip.livedoor.com/json/comments?link="+this._url; | |
var t = this; | |
jQuery.get( jsonUrl, {}, function(data) { | |
if( data.Comments && data.Comments.length > 0 ) { | |
t.displayResult(CmdUtils.renderTemplate(template, data)); | |
} else { | |
t.displayResult(); | |
} | |
}, "json"); | |
} | |
CmdUtils.CreateCommand({ | |
name: "sbm-comments", | |
description: "Browse SBM comments", | |
preview: function(pblock, directObject) { | |
var currentUrl = CmdUtils.getWindowInsecure().location.href; | |
var sbms = [HatenaBookmark, LivedoorClip].map(function(x) { return new x(pblock, currentUrl) }); | |
pblock.innerHTML = sbms.map(function(sbm){return sbm.html()}).join(""); | |
for each (sbm in sbms) { | |
sbm.fetch(pblock); | |
} | |
}, | |
execute: function() { /* do nothing */ }, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment