Created
June 22, 2014 14:26
-
-
Save butchi/911241a61e326301f4db to your computer and use it in GitHub Desktop.
クリックするたびにツイート文が変わるTwitterボタン ref: http://qiita.com/butchi_y/items/97ab31f6e5f37c08315c
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
<html> | |
<head> | |
<title>スーパーツイート</title> | |
</head> | |
<body> | |
<div class="twitter"> | |
<a href="https://twitter.com/share" class="twitter-share-button" data-via="butchi_y" data-hashtags="すごいパンチ" data-url="http://jsdo.it/butchi/super_tweet">Tweet</a> | |
</div> | |
<script type="text/javascript" charset="utf-8"> | |
window.twttr = (function (d,s,id) { | |
var t, js, fjs = d.getElementsByTagName(s)[0]; | |
if (d.getElementById(id)) return; js=d.createElement(s); js.id=id; | |
js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); | |
return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } }); | |
}(document, "script", "twitter-wjs")); | |
</script> | |
<script type="text/javascript" src="lib/jquery-1.10.2/js"></script> | |
<script type="text/javascript" src="lib/underscore-1.4.4/js"></script> | |
<script type="text/javascript" src="main.js"></script> | |
</body> | |
</html> |
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
var vocabulary = [ | |
'グレート', | |
'エクセレント', | |
'ネオ', | |
'超絶', | |
'ミラクル', | |
'豪快', | |
'ハイパー', | |
'マスター', | |
'ウルトラ', | |
'グランド', | |
'ワンダフル', | |
'アルティメット', | |
'メガ', | |
'ギガ', | |
'テラ', | |
'何となくすごい', | |
'面白' | |
]; | |
var $twitterElm; | |
var superTxt; | |
var tweetHtml; | |
$(function() { | |
$twitterElm = $(".twitter"); | |
tweetHtml = '<a href="https://twitter.com/share" class="twitter-share-button" data-via="butchi_y" data-hashtags="すごいパンチ" data-url="http://jsdo.it/butchi/super_tweet">Tweet</a>' | |
twttr.ready(function() { | |
setTweet(); | |
twttr.events.bind('click', function() { | |
setTweet(); | |
}); | |
}); | |
}); | |
function setTweet() { | |
var superPrefix = _.first(_.shuffle(vocabulary),10).join(''); | |
superTxt = superPrefix + 'パンチ'; | |
$twitterElm.html(tweetHtml); | |
$twitterElm.find('.twitter-share-button').attr('data-text', superTxt); | |
twttr.widgets.load(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment