Skip to content

Instantly share code, notes, and snippets.

@ne-sachirou
Created June 11, 2011 04:20
Show Gist options
  • Save ne-sachirou/1020245 to your computer and use it in GitHub Desktop.
Save ne-sachirou/1020245 to your computer and use it in GitHub Desktop.
@ichitaso title #js
// [Twitter / @ichitaso: @ne_sachirou 教えて欲しいこと:アメブロのタイトル下に http://bit.ly/lGFPAs のScriptを使用してはてブ、ツイッター、いいね!ボタンを設置してるんだけど、これにtumblrの共有ボタン http://bit.ly/jGkpvS を追加したい]( https://twitter.com/#!/ichitaso/status/79376845392457728 ,"")
// [Twitter / @ichitaso: @ne_sachirou アメブロはヘッドタグいじれないので、$.getScript("http://platform.tumblr.com/v1/share.js"); と記述して、var tumblur_btn = '<a href="~ って感じで記述しても表示しなかった]( https://twitter.com/#!/ichitaso/status/79378233409273856 ,"")
(function () {
var TWITTER_ID = 'ne_sachirou',
BLOG_TITLE = ' - Sachirou InoueのBlog';
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, // @param String:
title) { // @param String:
// @return String:
var hatena_btn, twitter_btn, tumblr_btn, ameba_btn,
mixi_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 + '" data-url="' + url + '">Tweet</a>';
if (/Firefox/i.test(navigator.userAgent)) {
tumblr_btn = '<a href="http://www.tumblr.com/share?v=3&u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title + BLOG_TITLE) + '" ' +
'title="Share on Tumblr" ' +
'style="display:inline-block; text-indent:-9999px; overflow:hidden; width:81px; height:20px; ' +
'background:url(\'http://platform.tumblr.com/v1/share_1.png\') top left no-repeat transparent;" ' +
'data-text="' + title + '" data-url="' + url + '">Share on Tumblr</a>';
} else {
tumblr_btn = '<a href="http://www.tumblr.com/share" title="Share on Tumblr" ' +
'style="display:inline-block; text-indent:-9999px; overflow:hidden; width:81px; height:20px; ' +
'background:url(\'http://platform.tumblr.com/v1/share_1.png\') top left no-repeat transparent;" ' +
'data-text="' + title + '" data-url="' + url + '">Share on Tumblr</a>';
}
ameba_btn = '<a rel="nofollow" target="_blank" href="http://stat100.ameba.jp/blog/proxy.html?longurl=' + url + '&title=' + title + '&type=now">' +
'<img src="http://stat100.ameba.jp/common_style/img/common/btn/btn_share_now.gif" alt="なうで紹介"></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, ameba_btn,
mixi_btn, gplus_btn, facebook_btn].join('&nbsp');
}
$(document).ready(function(){
var infos = [], // [[url:String, title:String], ...]
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, // @param Number:
node) { // @param Node: each Element;
infos[idx] = [node.toString(), node.text()];
});
target_node = $('.updatetime');
} else {
$('.foot a:contains("記事URL")').
each(function (idx, // @param Number:
node) { // @param Node: each Element;
infos[idx] = [node.toString(), $('div.entry h3.title').eq(idx).text()];
});
target_node = $('div.entry .theme');
}
$.each(infos, function (idx, // @param Number:
elm) { // @param Array: [url:String, title:String]
target_node.
eq(idx).
append(generate_button_text(elm[0], elm[1]));
});
});
}());
@ne-sachirou
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment