Difference between revisions of "MediaWiki:ReplaceWordWithLink.js"

From Tycoon Gaming
(Created page with "→‎Search Word: var list = ['Job Center', 'Grand Exchange', 'ATC', 'car dealership', 'job', 'skill', 'trucker']; →‎Replace Word (Link): var replacelist = ['Job_Center', 'Gra...")
 
Line 7: Line 7:
 
var path = window.location.search;
 
var path = window.location.search;
 
edit = path.search('&action=edit');
 
edit = path.search('&action=edit');
console.log(edit);
 
 
if (edit == -1){
 
if (edit == -1){
 
for (var i = 0; i < list.length; i++){
 
for (var i = 0; i < list.length; i++){
Line 17: Line 16:
 
}
 
}
 
} else {
 
} else {
console.log('Is in Editor');
 
 
}
 
}
 
}
 
}
 
Replace();
 
Replace();

Revision as of 21:41, 10 October 2019

/*Search Word*/
var list = ['Job Center', 'Grand Exchange', 'ATC',  'car dealership', 'job', 'skill', 'trucker'];
/*Replace Word (Link)*/
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');
	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 {
	}
}
Replace();