Difference between revisions of "MediaWiki:Common.js"

From Tycoon Gaming
m (Added js to rename PageTitles)
 
(62 intermediate revisions by 2 users not shown)
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:Middleclick.js&action=raw&ctype=text/javascript');
var port = ['30120', '30122', '30123', '30124', '30125','30120', '30122', '30123', '30124', '30125'];
+
mw.loader.load( '/wiki/index.php?title=MediaWiki:LastPage.js&action=raw&ctype=text/javascript');
var server_number = '';
+
mw.loader.load( '/wiki/index.php?title=MediaWiki:MoveTOC.js&action=raw&ctype=text/javascript');
var server_uptime = '';
+
mw.loader.load( '/wiki/index.php?title=MediaWiki:MainMenu.js&action=raw&ctype=text/javascript');
window.save = 0;
+
mw.loader.load( '/wiki/index.php?title=MediaWiki:PageSpecific.js&action=raw&ctype=text/javascript');
window.output = [];
+
 
window.string = '';
+
 
window.element = document.getElementById("content-container");
+
$(document).ready(function() {
element.classList.add("server-status");
+
if ( window.location !== window.parent.location ) {  
function server(){
+
const elem = document.getElementById('p-personal-container');
      for(var i = 0; i <= 9; i++) {
+
elem.style.display = 'none';
            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)
+
//RenamePageTitle via Template
      .then(
+
mw.hook('wikipage.content').add(function($content) {
             function(response) {
+
    // Search for the RenameTitle div on the page
                  if (response.status !== 200) {
+
    var renameTitleDiv = $content.find('#RenameTitle');
                              console.log('Looks like there was a problem. Status Code: ' +
+
    if (renameTitleDiv.length) {
                              response.status);
+
        var newTitle = renameTitleDiv.text();
                        return;
+
        // If found and not empty, change the firstHeading element's text
                  }
+
        var firstHeading = document.getElementById('firstHeading');
 +
        if (firstHeading && newTitle) {
 +
             firstHeading.textContent = newTitle;
 +
        }
 +
    }
 +
});
 +
 
 +
 
 +
/*
 +
// Create a new script element
 +
var darkReaderScript = document.createElement('script');
 +
 
 +
// Set the source of the script to the DarkReader URL
 +
darkReaderScript.src = 'https://unpkg.com/[email protected]/darkreader.js';
 +
 
 +
// Define what to do once the script has loaded
 +
darkReaderScript.onload = function() {
 +
    // Check if DarkReader is defined and enable it
 +
    if (typeof DarkReader !== 'undefined') {
 +
        DarkReader.enable();
 +
    } else {
 +
        console.error('DarkReader failed to load');
 +
    }
 +
};
 +
 
 +
// Handle any errors that occur during script loading
 +
darkReaderScript.onerror = function() {
 +
    console.error('An error occurred while loading DarkReader');
 +
};
  
                  // Examine the text in the response
+
// Append the script element to the document head
                  response.json().then(function(data) {
+
document.head.appendChild(darkReaderScript);
                        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();
 

Latest revision as of 20:42, 9 February 2024

mw.loader.load( '/wiki/index.php?title=Mediawiki:Middleclick.js&action=raw&ctype=text/javascript');
mw.loader.load( '/wiki/index.php?title=MediaWiki:LastPage.js&action=raw&ctype=text/javascript');
mw.loader.load( '/wiki/index.php?title=MediaWiki:MoveTOC.js&action=raw&ctype=text/javascript');
mw.loader.load( '/wiki/index.php?title=MediaWiki:MainMenu.js&action=raw&ctype=text/javascript');
mw.loader.load( '/wiki/index.php?title=MediaWiki:PageSpecific.js&action=raw&ctype=text/javascript');


$(document).ready(function() {
	if ( window.location !== window.parent.location ) { 
		const elem = document.getElementById('p-personal-container');
		elem.style.display = 'none';
	}
});

//RenamePageTitle via Template
mw.hook('wikipage.content').add(function($content) {
    // Search for the RenameTitle div on the page
    var renameTitleDiv = $content.find('#RenameTitle');
    if (renameTitleDiv.length) {
        var newTitle = renameTitleDiv.text();
        // If found and not empty, change the firstHeading element's text
        var firstHeading = document.getElementById('firstHeading');
        if (firstHeading && newTitle) {
            firstHeading.textContent = newTitle;
        }
    }
});


/*
// Create a new script element
var darkReaderScript = document.createElement('script');

// Set the source of the script to the DarkReader URL
darkReaderScript.src = 'https://unpkg.com/[email protected]/darkreader.js';

// Define what to do once the script has loaded
darkReaderScript.onload = function() {
    // Check if DarkReader is defined and enable it
    if (typeof DarkReader !== 'undefined') {
        DarkReader.enable();
    } else {
        console.error('DarkReader failed to load');
    }
};

// Handle any errors that occur during script loading
darkReaderScript.onerror = function() {
    console.error('An error occurred while loading DarkReader');
};

// Append the script element to the document head
document.head.appendChild(darkReaderScript);
*/