Created
October 31, 2011 07:30
-
-
Save hail2u/1327071 to your computer and use it in GitHub Desktop.
a[rel="bookmark"]探してはてブのカウントをくっつける
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
/*! | |
* 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