js
";
var category_div = document.querySelector("div.categories");
category_div.innerHTML = "
" + category_div.innerHTML;
}
// è¦åºã
function createSection() {
var sectionList = "";
var sectionCurrentLevel = 0;
$(".entry-content h2,.entry-content h3,.entry-content h4").each(function(i){
var idName = "section" + i;
$(this).attr("id",idName);
var level = 0;
if (this.nodeName.toLowerCase() === "h3") {
level = 1;
} else if (this.nodeName.toLowerCase() === "h4") {
level = 2;
}
while (sectionCurrentLevel < level) {
sectionList += '
';
sectionCurrentLevel++;
}
while (sectionCurrentLevel > level) {
sectionList += "
";
sectionCurrentLevel--;
}
sectionList += '
' + $(this).text() + '';
});
if ($(".entry-content h2,.entry-content h3,.entry-content h4").length >= 2){
$("
ç®æ¬¡
" + sectionList + "
").prependTo(".entry-content");
}
$('.sectionList a').on("click", function() {
$('html,body').animate({scrollTop: $(this.hash).offset().top}, 1000);
return false;
});
}
// nofollowãã¤ãã
function addNofollow() {
$('.entry-footer').find('.hatena-star-star-container').find('a').attr('rel', 'nofollow');
$('dd div.info').find('a').attr('rel', 'nofollow');
}
// ã«ã¼ãã®å¹
ãåçã«èª¿æ´
function editCard() {
var width = $("#main-inner").width();
$(".entry-content iframe").each(function(i) {
var afterWidth = (parseInt(width) - 10);
$(this).css({"max-width": afterWidth});
});
}
// ãã¡ã¤ã³ç§»è¡åã®ã¯ã¦ããªã³ã¯
function createOldHatebuLink() {
var path = location.pathname;
if (path.indexOf('/entry/') === -1)
return;
var OLD_DOMAIN = "treeapps.hatenablog.com";
var oldUrl = "http://" + OLD_DOMAIN + path;
var apiUrl = "https://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 = "https://b.hatena.ne.jp/entry/" + OLD_DOMAIN + path;
var html = "
ãã¡ã¤ã³ç§»è¡åã®ã¯ã¦ãæ° " + count + " 件";
$(".js-old-domain-hatebu-count-container").html(html);
}
}
});
}
// TOPãã¼ã¸ã§ã¯SNSãã¿ã³ãé表示
if (location.pathname === '/') {
$('.social-buttons').remove();
$('.customized-footer').remove();
}
// ãããã°ãæ¤ç´¢ãã®ãããã¼ãåé¤
//$('.hatena-module.hatena-module-search-box .hatena-module-title').remove();
// Facebookã®ã·ã§ã¢æ°ãåå¾
function countFacebook(url, selector) {
$.ajax({
url:'https://graph.facebook.com/',
dataType:'jsonp',
data:{
id:url
}
}).success(function(res){
if ( res.share && res.share.share_count ) {
$( selector ).text( res.share.share_count );
} else {
$( selector ).text( 0 );
}
});
}
//ã¯ã¦ãªããã¯ãã¼ã¯ã§ã¯ã¦ãæ°ãåå¾
function countHatebu(url, selector) {
$.ajax({
url:'https://b.hatena.ne.jp/entry.count?callback=?',
dataType:'jsonp',
data:{
url:url
}
}).success(function(res){
$(selector).text( res || 0 );
});
}
addNofollow();
createBreadcrumb();
// createSection();
editCard();
createOldHatebuLink();
countFacebook($('#Permalink').val(), ".facebook-count");
countHatebu($('#Permalink').val(), ".hatebu-count");
})(jQuery);