Twitter Auto Show New Tweets

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
	});
}