Skip to content

Instantly share code, notes, and snippets.

@csim
Last active August 29, 2015 13:58
Show Gist options
  • Save csim/10285505 to your computer and use it in GitHub Desktop.
Save csim/10285505 to your computer and use it in GitHub Desktop.
Embed tweets to blog
<div id="tweet"></div>
<script type="text/javascript">
function urlize(input) {
var exp = /(\b(https?|ftp|file):\/\/([-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]))/ig;
output = input.replace(exp,'<a href="$1">$3</a>');
return output;
}
function tweep(input) {
var exp = /(\@(\w+?)) /ig;
output = input.replace(exp,'<a href="http://www.twitter.com/$2">$1</a> ');
return output;
}
</script>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var url = 'http://api.twitter.com/1/statuses/user_timeline/<username>.json?callback=?'
$.getJSON(url, function(data) {
$("#tweet").html(tweep(urlize(data[0].text)));
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
var u = 'techhike';
var url = 'http://api.twitter.com/1/statuses/user_timeline/'
+ u + '.json?callback=?';
$.getJSON(url, function(data) {
$("#tweet").html(data[0].text));
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment