-
-
Save dalager/988557 to your computer and use it in GitHub Desktop.
Simple tweet rotator
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"> | |
</script> | |
<script type="text/javascript" charset="utf-8"> | |
var query = 'askhybel'; | |
$(function() { | |
$.getJSON("http://search.twitter.com/search.json?callback=?&q=" + query, | |
function (r) { | |
setResults(r); | |
}); | |
}); | |
var results = []; | |
var index = 0; | |
function setResults(data) { | |
results = data.results; | |
update(); | |
} | |
function setTweet(result) { | |
$("#image").attr("src" , result.profile_image_url); | |
$("#name").text(result.from_user); | |
$(".userlink").attr('href','http://twitter.com/'+result.from_user).attr('target','_blank'); | |
var text = result.text.replace(/(https?:\/\/[^\s]+)/g,'<a target="_blank" href="$1">$1</a>'); | |
text = text.replace(/@([a-z0-9]*)/g,'<a target="_blank" href="http://twitter.com/$1">@$1</a>'); | |
$("#text").html(text); | |
} | |
function update() { | |
setTweet(results[index]); | |
index += 1; | |
if(index == results.length) { | |
index = 0; | |
} | |
setTimeout(update,15000); | |
} | |
</script> | |
<body> | |
<a class="userlink"><img id="image" /></a> | |
<a class="userlink" href="#"><h2 id="name"></h2></a> | |
<p id="text"></p> | |
</body> | |
</html> |
@@ 9
- $.getJSON("http://search.twitter.com/search.json?callback=?&q=" + query,
- $.getJSON("https://api.twitter.com/1.1/search/tweets.json?q=" + query,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice and simple, thanks you!