Difference between revisions of "MediaWiki:Common.js"

From Tycoon Gaming
m (Added js to rename PageTitles)
 
(60 intermediate revisions by 2 users not shown)
Line 1: Line 1:
mw.loader.load( '/wiki/index.php?title=MediaWiki:ServerList.js&action=raw&ctype=text/javascript');
+
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');
  
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'];
+
$(document).ready(function() {
var edit = -1;
+
if ( window.location !== window.parent.location ) {  
function Replace(){
+
const elem = document.getElementById('p-personal-container');
var path = window.location.search;
+
elem.style.display = 'none';
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();
+
 
 +
//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);
 +
*/

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);
*/