Skip to content

Instantly share code, notes, and snippets.

@rubenfonseca
Created December 27, 2009 23:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenfonseca/264454 to your computer and use it in GitHub Desktop.
Save rubenfonseca/264454 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
if(!("WebSocket" in window)) {
alert("Sorry, the build of your browser does not support WebSockets. Please use latest Chrome or Webkit nightly");
return;
}
ws = new WebSocket("ws://localhost:8080/");
ws.onmessage = function(evt) {
data = eval("(" + evt.data + ")");
var p = $("<div class='tweet' style='display:none'><div class='content'><a class='main-screenname' href='http://www.twitter.com/" + data.user.screen_name + "/status/" + data.id + "' target='_blank'>" + data.user.screen_name + "</a> " + data.text + "</div></div>");
if($('#tweets div.tweet').size() > 15) {
$('#tweets div.tweet:last').slideDown(100, function() {
$(this).remove();
});
}
$('#tweets').prepend(p);
p.slideDown(140);
};
});
@kaareal
Copy link

kaareal commented Jun 14, 2011

may i suggest, that you replace eval with JSON.parse.
unless i am missing something there is no reason to use eval

@rubenfonseca
Copy link
Author

yes you are totally right, thank you!

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