Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!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>
Add Comment
Please, Sign In to add comment