Twitter Auto Show New Tweets

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Twitter Auto Show New Tweets
// @author Denis Lugowski
// @description Shows new incoming tweets. Adds a button to jump to the last tweet before adding new ones.
// @include http://www.twitter.com/*
// @version 1.0
// @namespace https://greasyfork.org/users/96649
// ==/UserScript==

// -------------- VARIABLES -------------- //
var tweets       = document.getElementsByClassName("stream-item");
var numTweets    = tweets.length;

// -------------- INTERVALS, TIMEOUTS -------------- //
setInterval(function(){
	if (document.querySelector('.new-tweets-bar') !== null) {
		document.getElementsByClassName("new-tweets-bar")[0].click();
		tweets = document.getElementsByClassName("stream-item");
		appendListElement(tweets.length - numTweets);
		numTweets = tweets.length;
	}
}, 5000);

// -------------- FUNCTIONS -------------- //
function appendListElement(numNewTweets) {
	var li              = document.createElement('li');
	var navigation      = document.getElementById("global-actions");
	var oldNotification = document.getElementById("new_tweets_notification");

	if (oldNotification !== null)
		navigation.removeChild(oldNotification);

	li.id = "new_tweets_notification";
	li.innerHTML = '<a role="button" href="#lastTweet" id="scrollToTweet" data-placement="bottom" data-original-title="">\
		<span class="Icon Icon--arrowDown Icon--large"></span>\
		<span class="text">' + numNewTweets + ' new Tweets</span></a>';

	navigation.appendChild(li);

	// inline eventlistener not working
	document.getElementById("scrollToTweet").addEventListener('click', function() {
		tweets[numNewTweets].scrollIntoView(true);
	});
}