Last active
August 29, 2015 14:25
-
-
Save treetips/ba2094d436c81f481f4f 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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script> | |
(function($) { | |
var path = location.pathname; | |
if (path.indexOf('/entry/') == -1) | |
return; | |
var OLD_DOMAIN = "あなたの旧ドメインを入力して下さい。(例)treeapps.hatenablog.com"; | |
var oldUrl = "http://" + OLD_DOMAIN + path; | |
var apiUrl = "http://api.b.st-hatena.com/entry.count?url=" + encodeURIComponent(oldUrl); | |
$.ajax({ | |
type: 'GET', | |
url: apiUrl, | |
dataType: 'jsonp', | |
jsonpCallback: 'callback', | |
success: function(count){ | |
if (count && 0 < parseInt(count)) { | |
var linkUrl = "http://b.hatena.ne.jp/entry/" + OLD_DOMAIN + path; | |
var html = "<a href=\"" + linkUrl + "\" target=\"_blank\" rel=\"nofollow\" class=\"js-old-domain-hatebu-count-link\">ドメイン移行前のはてブ数 " + count + " 件</a>"; | |
$(".js-old-domain-hatebu-count-container").html(html); | |
} | |
} | |
}); | |
})(jQuery); | |
</script> | |
<style> | |
/* 旧はてブ数コンテナ */ | |
.js-old-domain-hatebu-count-container { | |
margin: 7px 0px 7px 0px; | |
width: 100%; | |
text-align: center; | |
} | |
/* 旧はてブ数リンク */ | |
.js-old-domain-hatebu-count-link { | |
font-size: 20px; | |
font-weight: bold; | |
background-color: #00A5DE; | |
border: 2px solid #3498db; | |
padding: 1px 12px; | |
color: #f7fcfe !important; | |
display: block; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment