User:BilkaBot/common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* 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() {
console.log(document.getElementById("active-users"));
if (document.getElementById("active-users")!== null) {
console.log("yay");
$.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.' );
}
});
}
};