Skip to content

Instantly share code, notes, and snippets.

@whs
Created October 23, 2010 08:55
Show Gist options
  • Save whs/641962 to your computer and use it in GitHub Desktop.
Save whs/641962 to your computer and use it in GitHub Desktop.
Barcampbangkok4 twitter client
<!doctype html>
<html>
<head>
<title>Barcampbangkok 4 -Twitter client</title>
<script src="jquery.js"></script>
<script src="sha1.js"></script>
<script src="oauth.js"></script>
<script src="twitter.js"></script>
<script src="render.js"></script>
<link rel="stylesheet" href="render.css">
<script>
var tw, lastId = 1;
function rndTweet(x){
return renderTweet(x).data("data", x).click(function(){
$("#input").val("@"+$(this).data("data").user.screen_name+" ").get(0).focus()a;
});
}
function tweet(msg){
tw.post("statuses/update", {status: msg}, function(x){
if(x.id > lastId) lastId = x.id;
rndTweet(x).prependTo("#timeline");
});
}
function loadTimeline(){
tw.get("statuses/home_timeline", {count: 200, since_id: lastId}, function(x){
x.reverse().forEach(function(x){
if(x.id > lastId) lastId = x.id;
rndTweet(x).prependTo("#timeline");
});
});
}
$(function(){
tw = new Twitter();
if(!localStorage.twitterKey){
if(!localStorage.tmp){
tw.oauth(function(i){
localStorage.tmp = JSON.stringify(i.data);
window.location = i.url;
});
}else{
pin = prompt("PIN?");
data = JSON.parse(localStorage.tmp);
tw.oauth2(pin, data, function(x){
if(x){
localStorage.twitterKey = tw.consumer.token;
localStorage.twitterSecret = tw.consumer.tokenSecret;
}else{
alert("Auth fail!");
}
window.location.reload();
});
}
return;
}
tw = new Twitter(localStorage.twitterKey, localStorage.twitterSecret);
loadTimeline();
setInterval(loadTimeline, 30000);
$("#input").keydown(function(e){
if(e.which ==13){
tweet($(this).val());
$(this).val("");
}
});
});
</script>
</head>
<body>
<input id="input" />
<hr />
<div id="timeline"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment