User:BilkaBot/common.js: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Blanked the page)
(testing better version of main page active user display that doesn't throw an error on every other page)
Line 1: Line 1:
/* Script in here will be executed when the page is "ready" */
$(document).ready(getNumberOfActiveUsers);


/* show correct number of active users on the main page */
function getNumberOfActiveUsers() {
if ($("#active-users")) {
$.ajax({
url: 'https://wiki.factorio.com/api.php',
data: {
format: 'json',
action: 'query',
list: 'allusers',
aulimit: 500,
auactiveusers: true
},
dataType: 'json',
type: 'GET',
success: function(data) {
var numberOfActiveUsers = data.query.allusers.length;
document.getElementById("active-users").innerHTML = numberOfActiveUsers.toString();
console.log(numberOfActiveUsers)
},
error: function(xhr) {
console.log( 'Error: Request failed.' );
}
});
}
};

Revision as of 09:09, 2 July 2017

/* Script in here will be executed when the page is "ready" */
$(document).ready(getNumberOfActiveUsers);

/* show correct number of active users on the main page */

function getNumberOfActiveUsers() {
	if ($("#active-users")) {
		$.ajax({
			url: 'https://wiki.factorio.com/api.php',
			data: {
				format: 'json',
				action: 'query',
				list: 'allusers',
				aulimit: 500,
				auactiveusers: true
			},
			dataType: 'json',
			type: 'GET',
			success: function(data) {
				var numberOfActiveUsers = data.query.allusers.length;
				document.getElementById("active-users").innerHTML = numberOfActiveUsers.toString();
				console.log(numberOfActiveUsers)
			},
			error: function(xhr) {
				console.log( 'Error: Request failed.' );
			}
		});
	}
};