Revision as of 17:30, 9 October 2019 by Donald (talk | contribs)

MediaWiki:Common.js

From Tycoon Gaming

Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* 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 > 1680){
		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();