User:Technical 13/Scripts/Jobs.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Technical 13/Scripts/Jobs. |
var oldUsers = -1, oldPages = -1, oldJobs = -1, oldMms = -1;
function stopRefreshing() {
clearInterval( refreshStats );
$( '#stopButton' ).replaceWith( '<b>Last updated</b>' );
}
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 = '<tr><td>Total users</td><td style="text-align: right;">' +
statPath.users.toLocaleString() +
'</td><td style="text-align: right;">' + ( statPath.users -oldUsers ).toLocaleString() + '</td></tr>';
userInfo += '<tr><td>Active users</td><td colspan="2" style="text-align: center;">' +
( Math.round( statPath.activeusers / statPath.users * 1000000 ) / 10000 ) + '%</td></tr>';
userInfo += '<tr><td>Admins</td><td colspan="2" style="text-align: center;">' +
( Math.round( statPath.admins / statPath.users * 1000000 ) / 10000 ) + '%</td></tr>';
var pageInfo = '<tr><td>Total pages</td><td style="text-align: right;">' +
statPath.pages.toLocaleString() +
'</td><td style="text-align: right;">' + ( statPath.pages - oldPages ).toLocaleString() + '</td></tr>';
pageInfo += '<tr><td>Articles</td><td colspan="2" style="text-align: center;">' +
( Math.round( statPath.articles / statPath.pages * 1000000 ) / 10000 ) + '%</td></tr>';
pageInfo += '<tr><td>Images</td><td colspan="2" style="text-align: center;">' +
( Math.round( statPath.images / statPath.pages * 1000000 ) / 10000 ) + '%</td></tr>';
var jobInfo = '<tr><td>Queued jobs</td><td style="text-align: right;">' +
statPath.jobs.toLocaleString() +
'</td><td style="text-align: right;">' + ( statPath.jobs - oldJobs ).toLocaleString() + '</td></tr>';
var mmsInfo = '<tr><td>MMS Queue</td><td style="text-align: right;">' +
statPath[ 'queued-massmessages' ] +
'</td><td style="text-align: right;">' + ( statPath[ 'queued-massmessages' ] - oldMms ).toLocaleString() + '</td></tr>';
var displayInfo = '<table style="width: 100%;" border="1">';
displayInfo += '<tr><th style="font-variant: small-caps; font-size: 14px;">stat</th>' +
'<th style="font-variant: small-caps; font-size: 14px;">value</th>' +
'<th style="font-variant: small-caps; font-size: 14px;">change</th></tr>';
displayInfo += userInfo;
displayInfo += pageInfo;
displayInfo += jobInfo;
displayInfo += mmsInfo;
var nowTimeDate = new Date( Date.now() );
displayInfo += '<tr><td colspan="3" style="font-size: larger; text-align: center;"><a id="stopButton" href="#stopUpdating" onClick="stopRefreshing();">Stop updating</a>: ' + nowTimeDate.toLocaleTimeString() + '</td></tr>';
displayInfo += '<tr><td colspan="3" style="font-size: larger; text-align: center;">' +
'<a href="/wiki/User:Technical_13/Scripts/Jobs" title="User:Technical 13/Scripts/Jobs">Documentation</a>' +
'</td></tr></table>';
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 );