User:Kaldari/toolbaralert.js

// Adapted from code at http://augiegardner.wordpress.com/2012/09/17/javascript-text-typing-animation/ 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+=" "+text[i]+" " }			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; ' ); texttype( 'mw-echo-alert', '(New messages have arrived)', 50, 0 ); } } ); } )( jQuery, mediaWiki );