/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> String.prototype.parseURL = function() { return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(url) { return url.link(url); }); }; String.prototype.parseUsername = function() { return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) { var username = u.replace("@","") return u.link("http://twitter.com/"+username); }); }; String.prototype.parseHashtag = function() { return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) { var tag = t.replace("#","%23") return t.link("http://search.twitter.com/search?q="+tag); }); }; function twitterCallback2(obj) { var twitters = obj; var statusHTML = ""; var username = ""; for (var i=0; i<twitters.length; i++){ username = twitters[i].user.screen_name; statusHTML += ('<li>'+twitters[i].text+'</li>'); } document.getElementById('tweets').innerHTML = statusHTML.parseURL().parseUsername().parseHashtag(); } </script> <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/YOURUSERNAME.json?callback=twitterCallback2&count=10"></script>