Skip to content

Instantly share code, notes, and snippets.

@sysnakamura
Created May 7, 2016 20:20
Show Gist options
  • Save sysnakamura/31ec3cd31f6b3a8d2663a15d122cdd08 to your computer and use it in GitHub Desktop.
Save sysnakamura/31ec3cd31f6b3a8d2663a15d122cdd08 to your computer and use it in GitHub Desktop.
はてなブログの記事下に設置するシェアボタンの Jquery
<!--JQueryを使用-->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!--シェア数の取得-->
<script>
//はてなブックマークのシェア数
function getHatenaBookmarkCount(entryUrl, selcter) {
entryUrl = 'http://api.b.st-hatena.com/entry.count?url=' + encodeURIComponent(entryUrl)
$.ajax({
url:entryUrl,
dataType:'jsonp',
}).then(
function(result){ $(selcter).text(result || 0); },
function(){ $(selcter).text('0'); }
);
}
//Facebookのシェア数
function getFacebookCount(entryUrl, selcter) {
entryUrl = 'https://graph.facebook.com/' + encodeURIComponent(entryUrl)
$.ajax({
url:entryUrl,
dataType:'jsonp'
}).then(
function(result){ $(selcter).text(result.shares || 0); },
function(){ $(selcter).text('0'); }
);
}
$(function(){
getHatenaBookmarkCount('{Permalink}', '.hatena-bookmark-count');
getFacebookCount('{Permalink}', '.facebook-count');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment