Difference between revisions of "MediaWiki:Common.js"
From Tycoon Gaming
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
+ | var port = ['30120', '30122', '30123', '30124', '30125','30120', '30122', '30123', '30124', '30125']; | ||
+ | var server_number = ''; | ||
+ | var server_uptime = ''; | ||
+ | window.save = 0; | ||
+ | window.output = []; | ||
+ | window.string = ''; | ||
+ | window.element = document.getElementById("content-container"); | ||
+ | element.classList.add("server-status"); | ||
+ | function server(){ | ||
+ | for(var i = 0; i <= 9; i++) { | ||
+ | if(i <= 4){ | ||
+ | var url = 'http://server.tycoon.community:' + port[i] + '/status/widget/players.json'; | ||
+ | } else { | ||
+ | var url = 'http://na.tycoon.community:' + port[i] + '/status/widget/players.json'; | ||
+ | } | ||
+ | fetching(i, url); | ||
+ | }; | ||
+ | } | ||
+ | function Output(){ | ||
+ | if(window.save == 10){ | ||
+ | window.string += '<div class="server-serverlist">'; | ||
+ | window.string += '<div class="serverlist-title">Server Status</div>'; | ||
+ | for(var ar = 0; ar < window.output.length; ar++){ | ||
+ | for(var k = 0; k < window.output[ar].length;k++){ | ||
+ | window.string += window.output[ar][k]; | ||
+ | }; | ||
+ | }; | ||
+ | window.string += '</div>'; | ||
+ | var site = ''; | ||
+ | site += window.string; | ||
+ | site += window.element.innerHTML; | ||
+ | console.log('Server List made by Donald 🦆#3216'); | ||
+ | window.element.innerHTML = site; | ||
+ | }; | ||
+ | } | ||
+ | function fetching(i, url){ | ||
+ | fetch(url) | ||
+ | .then( | ||
+ | function(response) { | ||
+ | if (response.status !== 200) { | ||
+ | console.log('Looks like there was a problem. Status Code: ' + | ||
+ | response.status); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // Examine the text in the response | ||
+ | response.json().then(function(data) { | ||
+ | window.output[i] = []; | ||
+ | var l = 0; | ||
+ | window.output[i][l] = '<div class="server"><div class="server-'; l++; | ||
+ | window.output[i][l] = data.server.number; l++; | ||
+ | window.output[i][l] = '"><div class="server-title">'; l++; | ||
+ | window.output[i][l] = 'Server: '; l++; | ||
+ | window.output[i][l] = data.server.number; l++; | ||
+ | window.output[i][l] = '</div>'; l++; | ||
+ | window.output[i][l] = '<div class="server-uptime">'; l++; | ||
+ | window.output[i][l] = 'Server Uptime: '; l++; | ||
+ | window.output[i][l] = data.server.uptime; l++; | ||
+ | window.output[i][l] = '</div>'; l++; | ||
+ | window.output[i][l] = '<div class="server-players">Players Online: '; l++; | ||
+ | window.output[i][l] = data.players.length; l++; | ||
+ | window.output[i][l] = '/'; l++; | ||
+ | window.output[i][l] = data.server.limit; l++; | ||
+ | window.output[i][l] = '</div><br></div></div>'; l++; | ||
+ | window.save++; | ||
+ | Output(); | ||
+ | }); | ||
+ | } | ||
+ | ) | ||
+ | .catch(function(err) { | ||
+ | console.log('Fetch Error :-S', err); | ||
+ | }); | ||
+ | } | ||
+ | server(); |
Revision as of 22:03, 8 October 2019
/* Any JavaScript here will be loaded for all users on every page load. */ var port = ['30120', '30122', '30123', '30124', '30125','30120', '30122', '30123', '30124', '30125']; var server_number = ''; var server_uptime = ''; window.save = 0; window.output = []; window.string = ''; window.element = document.getElementById("content-container"); element.classList.add("server-status"); function server(){ for(var i = 0; i <= 9; i++) { if(i <= 4){ var url = 'http://server.tycoon.community:' + port[i] + '/status/widget/players.json'; } else { var url = 'http://na.tycoon.community:' + port[i] + '/status/widget/players.json'; } fetching(i, url); }; } function Output(){ if(window.save == 10){ window.string += '<div class="server-serverlist">'; window.string += '<div class="serverlist-title">Server Status</div>'; for(var ar = 0; ar < window.output.length; ar++){ for(var k = 0; k < window.output[ar].length;k++){ window.string += window.output[ar][k]; }; }; window.string += '</div>'; var site = ''; site += window.string; site += window.element.innerHTML; console.log('Server List made by Donald 🦆#3216'); window.element.innerHTML = site; }; } function fetching(i, url){ fetch(url) .then( function(response) { if (response.status !== 200) { console.log('Looks like there was a problem. Status Code: ' + response.status); return; } // Examine the text in the response response.json().then(function(data) { window.output[i] = []; var l = 0; window.output[i][l] = '<div class="server"><div class="server-'; l++; window.output[i][l] = data.server.number; l++; window.output[i][l] = '"><div class="server-title">'; l++; window.output[i][l] = 'Server: '; l++; window.output[i][l] = data.server.number; l++; window.output[i][l] = '</div>'; l++; window.output[i][l] = '<div class="server-uptime">'; l++; window.output[i][l] = 'Server Uptime: '; l++; window.output[i][l] = data.server.uptime; l++; window.output[i][l] = '</div>'; l++; window.output[i][l] = '<div class="server-players">Players Online: '; l++; window.output[i][l] = data.players.length; l++; window.output[i][l] = '/'; l++; window.output[i][l] = data.server.limit; l++; window.output[i][l] = '</div><br></div></div>'; l++; window.save++; Output(); }); } ) .catch(function(err) { console.log('Fetch Error :-S', err); }); } server();