User:Mooeypoo/NotificationsTest.js

$( document ).ready( function {	var echoApi = null,		currentCount = 0;

$.when( mw.loader.using( [ 'mediawiki.api.messages', 'mediawiki.jqueryMsg', 'ext.echo.api' ] ), $.ready ) .then( function {			// See https://www.mediawiki.org/wiki/Manual:Messages_API			return new mw.Api.loadMessagesIfMissing( [ 'echo-badge-count' ] );		} ) .then( function ( messages ) {			console.log( messages );			echoApi = new mw.echo.api.EchoApi;		} ); function fetchNotificationCount( type ) { return echoApi.fetchUnreadCount( 'local', type ); }	function updateBadgeCount( type, count, label ) { var $badge = $( 'pt-notifications-' + ( type === 'alert' ? 'alert' : 'notice' ) + ' a' );

label = label || count;

if ( !$badge.length ) { return; }		$badge .toggleClass( 'mw-echo-notifications-badge-all-read', !count ) .toggleClass( 'mw-echo-notifications-badge-long-label', label.length > 2 ) .attr( 'data-counter-num', count ) .attr( 'data-counter-text', label );

if ( currentCount !== count ) { currentCount = count;

// Fire badge count change hook mw.hook( 'ext.echo.badge.countChange' ).fire( type, currentCount, label ); }	} } );