User:BilkaBot/common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
function getNumberOfActiveUsers() { | function getNumberOfActiveUsers() { | ||
if (document.getElementById("active-users")) { | |||
if (document.getElementById("active-users") | |||
$.ajax({ | $.ajax({ | ||
url: 'https://wiki.factorio.com/api.php', | url: 'https://wiki.factorio.com/api.php', | ||
Line 22: | Line 20: | ||
var numberOfActiveUsers = data.query.allusers.length; | var numberOfActiveUsers = data.query.allusers.length; | ||
document.getElementById("active-users").innerHTML = numberOfActiveUsers.toString(); | document.getElementById("active-users").innerHTML = numberOfActiveUsers.toString(); | ||
}, | }, | ||
error: function(xhr) { | error: function(xhr) { |
Revision as of 10:20, 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 (document.getElementById("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();
},
error: function(xhr) {
console.log( 'Error: Request failed.' );
}
});
}
};