Twitter Auto Show New Tweets

Shows new incoming tweets. Adds a button to jump to the last tweet before adding new ones.

  1. // ==UserScript==
  2. // @name Twitter Auto Show New Tweets
  3. // @author Denis Lugowski
  4. // @description Shows new incoming tweets. Adds a button to jump to the last tweet before adding new ones.
  5. // @include http://www.twitter.com/*
  6. // @version 1.0
  7. // @namespace https://greasyfork.org/users/96649
  8. // ==/UserScript==
  9.  
  10. // -------------- VARIABLES -------------- //
  11. var tweets = document.getElementsByClassName("stream-item");
  12. var numTweets = tweets.length;
  13.  
  14. // -------------- INTERVALS, TIMEOUTS -------------- //
  15. setInterval(function(){
  16. if (document.querySelector('.new-tweets-bar') !== null) {
  17. document.getElementsByClassName("new-tweets-bar")[0].click();
  18. tweets = document.getElementsByClassName("stream-item");
  19. appendListElement(tweets.length - numTweets);
  20. numTweets = tweets.length;
  21. }
  22. }, 5000);
  23.  
  24. // -------------- FUNCTIONS -------------- //
  25. function appendListElement(numNewTweets) {
  26. var li = document.createElement('li');
  27. var navigation = document.getElementById("global-actions");
  28. var oldNotification = document.getElementById("new_tweets_notification");
  29.  
  30. if (oldNotification !== null)
  31. navigation.removeChild(oldNotification);
  32.  
  33. li.id = "new_tweets_notification";
  34. li.innerHTML = '<a role="button" href="#lastTweet" id="scrollToTweet" data-placement="bottom" data-original-title="">\
  35. <span class="Icon Icon--arrowDown Icon--large"></span>\
  36. <span class="text">' + numNewTweets + ' new Tweets</span></a>';
  37.  
  38. navigation.appendChild(li);
  39.  
  40. // inline eventlistener not working
  41. document.getElementById("scrollToTweet").addEventListener('click', function() {
  42. tweets[numNewTweets].scrollIntoView(true);
  43. });
  44. }