Skip to content

Instantly share code, notes, and snippets.

@cyokodog
Last active December 15, 2015 10:19
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 cyokodog/5244675 to your computer and use it in GitHub Desktop.
Save cyokodog/5244675 to your computer and use it in GitHub Desktop.
はてブカウントのリンクを挿入する jQuery プラグイン
.hatebu-count{
margin-left:2px;
font-weight:bold;
color:#ff5577;
}
(function($){
$.hatebuCount = function(url,callback){
$.ajax({
type: 'GET',
url: 'http://api.b.st-hatena.com/entry.count',
data: {
url : url
},
dataType: 'jsonp',
success: callback
});
}
$.fn.hatebuCount = function(){
this.each(function(){
var target = $(this);
$.hatebuCount(target.prop('href'),function(count){
!count ||
target.after('<a class="hatebu-count" target="_blank"/>').next().text(count+'user').prop({
'href' :
'http://b.hatena.ne.jp/entry/' +
target.prop('hostname') + '/' +
target.prop('pathname')
});
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment