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. */
+
mw.loader.load( '/wiki/index.php?title=MediaWiki:ServerList.js&action=raw&ctype=text/javascript');
var port = ['30120', '30122', '30123', '30124', '30125','30120', '30122', '30123', '30124', '30125'];
+
 
var server_number = '';
+
var list = ['Job Center', 'Grand Exchange', 'ATC', 'car dealership', 'job', 'skill', 'trucker'];
var server_uptime = '';
+
var replacelist = ['Job_Center', 'Grand_Exchange', 'Airline_Pilot#ATC_.28Air_Traffic_Control.29', 'Car_Dealer', 'Job_Center', 'Skill_Level_Tokens', 'Trucking'];
window.save = 0;
+
var edit = -1;
window.output = [];
+
function Replace(){
window.string = '';
+
var path = window.location.search;
window.element = document.getElementById("content-container");
+
edit = path.search('&action=edit');
element.classList.add("server-status");
+
console.log(edit);
function server(){
+
if (edit == -1){
      for(var i = 0; i <= 9; i++) {
+
for (var i = 0; i < list.length; i++){
            if(i <= 4){
+
var output;
                  var url = 'http://server.tycoon.community:' + port[i] + '/status/widget/players.json';
+
window.element = document.getElementById("bodyContent");
            } else {
+
var save = window.element.innerHTML;
                  var url = 'http://na.tycoon.community:' + port[i] + '/status/widget/players.json';
+
output = save.replace(' ' + list[i] + ' ', '<a href="/wiki/index.php/' + replacelist[i] + '">' + list[i] + '</a>');
            }
+
window.element.innerHTML = output;
            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 {
 
} else {
console.log('Mobile Device');
+
console.log('Is in Editor');
 
}
 
}
 
}
 
}
function fetching(i, url){
+
Replace();
      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 19:46, 9 October 2019

mw.loader.load( '/wiki/index.php?title=MediaWiki:ServerList.js&action=raw&ctype=text/javascript');

var list = ['Job Center', 'Grand Exchange', 'ATC',  'car dealership', 'job', 'skill', 'trucker'];
var replacelist = ['Job_Center', 'Grand_Exchange', 'Airline_Pilot#ATC_.28Air_Traffic_Control.29', 'Car_Dealer', 'Job_Center', 'Skill_Level_Tokens', 'Trucking'];
var edit = -1;
function Replace(){
	var path = window.location.search;
	edit = path.search('&action=edit');
	console.log(edit);
	if (edit == -1){
		for (var i = 0; i < list.length; i++){
			var output;
			window.element = document.getElementById("bodyContent");
			var save = window.element.innerHTML;
			output = save.replace(' ' + list[i] + ' ', '<a href="/wiki/index.php/' + replacelist[i] + '">' + list[i] + '</a>');
			window.element.innerHTML = output;
		}
	} else {
		console.log('Is in Editor');
	}
}
Replace();