Jump to content

User:Kaldari/toolbaralert2.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function texttype(targetDiv, text, intervalStart, intervalRange, callback){
	var textTyperID = ++window.textTyperID;
	window.textTyper[textTyperID] = new function(){
		var textFinished = false;
		this.init = function(){
		var innerString="";
			for(var i = 0; i < text.length; i++){
				innerString+="<span style='display:none;'>"+text[i]+"</span>"
			}
				document.getElementById(targetDiv).innerHTML = innerString;
				window.textTyper[textTyperID].type(0);
		}
		this.type = function(i){
			var target = document.getElementById(targetDiv).childNodes;
			if(i<text.length){
				var to = intervalStart-(intervalRange/2);
				var from = intervalStart+(intervalRange/2);
				var interval = Math.floor(Math.random()*(to-from+1)+from);
				target[i].style.display = 'inline';
				setTimeout(function(){
					window.textTyper[textTyperID].type(++i);
				},interval);
			}
			else{
				setTimeout(function(){
						textFinished=true;
				},3000);
				if(callback)
					callback();
			}
		}
	};
	window.textTyper[textTyperID].init();
}
(function() { /*Function to prep variables on page load */
	window.textTyperID=0;
	window.textTyper = new Array();
}
)();

( function( $, mw ) {
$(document).ready(function() {
	//$( '.usermessage' ).hide();
	var newMsgRevisionId = mw.config.get( 'wgUserNewMsgRevisionId' );
	if ( newMsgRevisionId ) {
		$( '#pt-mytalk a' ).append( ':&#160;<span id="mw-echo-alert"></span>' );
		$( '#pt-mytalk a' ).css( {
			'border-radius': '3px',
			'background-color': '#2e6ebe',
			'padding': '4px 10px',
'color': 'white'
		} );
		texttype('mw-echo-alert', 'You have new messages', 20, 0);
	}
} );
} )( jQuery, mediaWiki );