Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2011 23:06
Show Gist options
  • Save anonymous/1138525 to your computer and use it in GitHub Desktop.
Save anonymous/1138525 to your computer and use it in GitHub Desktop.
Amebloのタイトル下にSNSボタンを設置するコード
(function () {
var Twitter_ID = 'TwitterID',
BLOG_TITLE = '|BlogTittle';
if (!(/Trident|Firefox/i.test(navigator.userAgent))) {
navigator.userAgent = 'Mozilla/5.0(Windows NT 6.1;WOW64) AppleWebKit/534.30(KHTML,like Gecko) Chrome/12.0.742.91 Safari/534.30';
}
function generate_button_text(url, title) {
var hatena_btn, twitter_btn, tumblr_btn, mixi_btn,gshare_btn, gplus_btn, facebook_btn;
hatena_btn = '<a href="' + url + '" class="hatena-bookmark-button" data-hatena-bookmark-title="' + title + '" data-hatena-bookmark-layout="standard" title="このエントリーをはてなブックマークに追加">' + '<img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border:none;"/></a>';
twitter_btn = '<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="' + Twitter_ID + '" data-text="' + title + BLOG_TITLE + '" data-url="' + url + '">Tweet</a>';
if (/Firefox/i.test(navigator.userAgent)) {
tumblr_btn = '<a onclick="return popitup(this.href);" href="http://www.tumblr.com/share?v=3&u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title + BLOG_TITLE) + '" ' + 'title="Share on Tumblr" ' + 'style="display:inline-block;overflow:hidden;width:61px;height:20px;' + 'background:url(\'http://platform.tumblr.com/v1/share_2.png\') top left no-repeat transparent;" ' + 'data-text="' + title + BLOG_TITLE + '" data-url="' + url + '"></a>';
} else {
tumblr_btn = '<a target="_blank" href="http://www.tumblr.com/share" title="Share on Tumblr" ' + 'style="display:inline-block;;overflow:hidden;width:61px;height:20px;' + 'background:url(\'http://platform.tumblr.com/v1/share_2.png\') top left no-repeat transparent;" ' + 'data-text="' + title + BLOG_TITLE + '" data-url="' + url + '"></a>';
}
gshare_btn = '<a rel="nofollow" target="_blank" onclick="return popitup(this.href);" href="https://m.google.com/app/plus/x/?v=compose&hl=ja&content=' + title + BLOG_TITLE + '&nbsp;' + '-' + '&nbsp;' + url + '">' + '<img src="http://stat.ameba.jp/user_images/20110810/15/ichitaso/92/97/g/o0080002011407323579.gif" alt="Share on Google+" title="Share on Google+" width="80" height="20"></a>';
mixi_btn = '<a rel="nofollow" target="_blank" href="http://stat100.ameba.jp/blog/proxy.html?longurl=' + url + '&type=mixi">' + '<img src="http://stat100.ameba.jp/common_style/img/common/btn/btn_share_mixi.png" alt="mixiチェック"></a>';
gplus_btn = '<div class="g-plusone" size="medium" data-size="medium" data-count="true" href=' + url + '></div>';
facebook_btn = '<iframe src="http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent(url) + '&layout=button_count&show_faces=false&width=100&action=like&colorscheme=light&height=21" scrolling="no" ' + 'frameborder="0" style="border:none;overflow:hidden;width:100px;height:21px;" allowTransparency="true"></iframe>';
return [hatena_btn, twitter_btn, tumblr_btn, mixi_btn, gshare_btn, gplus_btn, facebook_btn].join('&nbsp');
}
$(document).ready(function () {
var infos = [],
target_node;
$.getScript('http://b.st-hatena.com/js/bookmark_button.js');
$.getScript('http://platform.twitter.com/widgets.js');
$.getScript('http://platform.tumblr.com/v1/share.js');
$.getScript("http://apis.google.com/js/plusone.js", function () {
{
lang: 'ja'
}
});
if (location.href.match(/^.+\/entrylist[\-0-9]*\.html$/g)) {
$('.newentrytitle a').each(function (idx, node) {
infos[idx] = [node.toString(), node.text()];
});
target_node = $('.updatetime');
} else {
$('.foot a:contains("記事URL")').each(function (idx, node) {
infos[idx] = [node.toString(), $("div.entry h3.title").eq(idx).text()];
});
target_node = $('div.entry .theme');
}
$.each(infos, function (idx, elm) {
target_node.eq(idx).append('&nbsp;&nbsp;&nbsp;' + generate_button_text(elm[0], elm[1]));
});
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment