Return to Snippet

Revision: 21810
at December 22, 2009 00:01 by levinet


Initial Code
<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>

Initial URL

                                

Initial Description

                                

Initial Title
Twitter JSON URL, Hashtag & User Parser

Initial Tags
url, javascript, js, json, user, twitter

Initial Language
JavaScript