Difference between revisions of "MediaWiki:Common.js"

From Tycoon Gaming
Line 19: Line 19:
 
}
 
}
 
function Output(){
 
function Output(){
      if(window.save == 10){
+
if(window.innerWidth > 1280){
            window.string += '<div class="server-serverlist">';
+
if(window.save == 10){
            window.string += '<div class="serverlist-title">Server Status</div>';
+
window.string += '<div class="server-serverlist">';
            for(var ar = 0; ar < window.output.length; ar++){
+
window.string += '<div class="serverlist-title">Server Status</div>';
                  for(var k = 0; k < window.output[ar].length;k++){
+
for(var ar = 0; ar < window.output.length; ar++){
                        window.string += window.output[ar][k];
+
for(var k = 0; k < window.output[ar].length;k++){
                  };
+
window.string += window.output[ar][k];
            };
+
};
            window.string += '</div>';
+
};
            var site = '';
+
window.string += '</div>';
            site += window.string;
+
var site = '';
            site += window.element.innerHTML;
+
site += window.string;
            console.log('Server List made by Donald 🦆#3216');
+
site += window.element.innerHTML;
            window.element.innerHTML = site;
+
console.log('Server List made by Donald 🦆#3216');
      };
+
window.element.innerHTML = site;
 +
};
 +
} else {
 +
console.log('Mobile Device');
 +
}
 
}
 
}
 
function fetching(i, url){
 
function fetching(i, url){

Revision as of 17:26, 9 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.innerWidth > 1280){
		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;
		};
	} else {
		console.log('Mobile Device');
	}
}
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();