Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created October 31, 2011 07:30
Show Gist options
  • Save hail2u/1327071 to your computer and use it in GitHub Desktop.
Save hail2u/1327071 to your computer and use it in GitHub Desktop.
a[rel="bookmark"]探してはてブのカウントをくっつける
/*!
* hatena-bookmark-count.js
*
* Copyright (c) 2011 Kyo Nagashima <kyo@hail2u.net>
* This library licensed under MIT license:
* http://opensource.org/licenses/mit-license.php
*/
/*global jQuery, $ */
$(function () {
"use strict";
$("a[rel='bookmark']").each(function () {
var $_ = $(this),
url = $_.prop("href");
$.getJSON("http://api.b.st-hatena.com/entry.count?callback=?", {
"url": url
}, function (d) {
if (typeof d === "number") {
$_.parent().before(
$("<aside/>").addClass("bookmark-count").append(
$("<p/>").append(
$("<a/>").attr({
"href": "http://b.hatena.ne.jp/entry/" + url
}).append(d)
)
)
);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment