Guest User

Untitled

a guest
Jun 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Barcampbangkok 4 -Twitter client</title>
  5. <script src="jquery.js"></script>
  6. <script src="sha1.js"></script>
  7. <script src="oauth.js"></script>
  8. <script src="twitter.js"></script>
  9. <script src="render.js"></script>
  10. <link rel="stylesheet" href="render.css">
  11. <script>
  12. var tw, lastId = 1;
  13. function rndTweet(x){
  14. return renderTweet(x).data("data", x).click(function(){
  15. $("#input").val("@"+$(this).data("data").user.screen_name+" ").get(0).focus()a;
  16. });
  17. }
  18. function tweet(msg){
  19. tw.post("statuses/update", {status: msg}, function(x){
  20. if(x.id > lastId) lastId = x.id;
  21. rndTweet(x).prependTo("#timeline");
  22. });
  23. }
  24. function loadTimeline(){
  25. tw.get("statuses/home_timeline", {count: 200, since_id: lastId}, function(x){
  26. x.reverse().forEach(function(x){
  27. if(x.id > lastId) lastId = x.id;
  28. rndTweet(x).prependTo("#timeline");
  29. });
  30. });
  31. }
  32. $(function(){
  33. tw = new Twitter();
  34. if(!localStorage.twitterKey){
  35. if(!localStorage.tmp){
  36. tw.oauth(function(i){
  37. localStorage.tmp = JSON.stringify(i.data);
  38. window.location = i.url;
  39. });
  40. }else{
  41. pin = prompt("PIN?");
  42. data = JSON.parse(localStorage.tmp);
  43. tw.oauth2(pin, data, function(x){
  44. if(x){
  45. localStorage.twitterKey = tw.consumer.token;
  46. localStorage.twitterSecret = tw.consumer.tokenSecret;
  47. }else{
  48. alert("Auth fail!");
  49. }
  50. window.location.reload();
  51. });
  52. }
  53. return;
  54. }
  55. tw = new Twitter(localStorage.twitterKey, localStorage.twitterSecret);
  56. loadTimeline();
  57. setInterval(loadTimeline, 30000);
  58. $("#input").keydown(function(e){
  59. if(e.which ==13){
  60. tweet($(this).val());
  61. $(this).val("");
  62. }
  63. });
  64. });
  65. </script>
  66. </head>
  67. <body>
  68. <input id="input" />
  69. <hr />
  70. <div id="timeline"></div>
  71. </body>
  72. </html>
Add Comment
Please, Sign In to add comment