User:Technical 13/Scripts/Jobs.js

var oldUsers = -1, oldPages = -1, oldJobs = -1, oldMms = -1;

function stopRefreshing() {

clearInterval( refreshStats );

$( '#stopButton' ).replaceWith( 'Last updated' );

}

function updateResults() {

new mw.Api().get( {

action: 'query',

meta: 'siteinfo',

siprop: 'statistics'

} ).done( function( siteStats ) {

var statPath = siteStats.query.statistics;

if ( oldUsers === -1 ) { oldUsers = statPath.users; }

if ( oldPages === -1 ) { oldPages = statPath.pages; }

if ( oldJobs === -1 ) { oldJobs = statPath.jobs; }

if ( oldMms === -1 ) { oldMms = statPath[ 'queued-massmessages' ]; }

var userInfo = 'Total users' +

statPath.users.toLocaleString() +

'' + ( statPath.users -oldUsers ).toLocaleString() + '';

userInfo += 'Active users' +

( Math.round( statPath.activeusers / statPath.users * 1000000 ) / 10000 ) + '%';

userInfo += 'Admins' +

( Math.round( statPath.admins / statPath.users * 1000000 ) / 10000 ) + '%';

var pageInfo = 'Total pages' +

statPath.pages.toLocaleString() +

'' + ( statPath.pages - oldPages ).toLocaleString() + '';

pageInfo += 'Articles' +

( Math.round( statPath.articles / statPath.pages * 1000000 ) / 10000 ) + '%';

pageInfo += 'Images' +

( Math.round( statPath.images / statPath.pages * 1000000 ) / 10000 ) + '%';

var jobInfo = 'Queued jobs' +

statPath.jobs.toLocaleString() +

'' + ( statPath.jobs - oldJobs ).toLocaleString() + '';

var mmsInfo = 'MMS Queue' +

statPath[ 'queued-massmessages' ] +

'' + ( statPath[ 'queued-massmessages' ] - oldMms ).toLocaleString() + '';

var displayInfo = '

';

displayInfo += '

' +

'

' +

'

';

displayInfo += userInfo;

displayInfo += pageInfo;

displayInfo += jobInfo;

displayInfo += mmsInfo;

var nowTimeDate = new Date( Date.now() );

displayInfo += '

';

displayInfo += '

stat value change
Stop updating: ' + nowTimeDate.toLocaleTimeString() + '
' +

'Documentation' +

'

';

mw.notify( $( displayInfo ), { title: 'Current enwp statistics:', tag: 'siteInfo', autoHide: false } );

oldUsers = statPath.users;

oldJobs = statPath.jobs;

oldMms = statPath[ 'queued-massmessages' ];

} );

};

updateResults();

var refreshStats = window.setInterval( updateResults, 15000 );