Difference between revisions of "MediaWiki:ReplaceWordWithLink.js"
From Tycoon Gaming
Line 15: | Line 15: | ||
/*output is my output Variable and Contains the Whole code with the changed word | /*output is my output Variable and Contains the Whole code with the changed word | ||
save.replace searches for the word with a ' ' in front and Behind it and replaces it then with the link and the Text Stays the same*/ | save.replace searches for the word with a ' ' in front and Behind it and replaces it then with the link and the Text Stays the same*/ | ||
− | + | /*save.replace(word i search for, replacement word/code*/ | |
+ | var word = ' ' + list[i] + ' '; | ||
+ | var reg = new RegExp(word, 'gi'); | ||
+ | var output = save.replace(reg, ' ' + '<a href="/wiki/index.php/' + replacelist[i] + '">' + list[i] + '</a>' + ' '); | ||
/*Here i overwrite the HTML in the Div with the new code*/ | /*Here i overwrite the HTML in the Div with the new code*/ | ||
window.element.innerHTML = output; | window.element.innerHTML = output; |
Revision as of 00:19, 12 October 2019
/*Search Word*/ var list = ['Job Center', 'Grand Exchange', 'ATC', 'car dealership', 'job', 'skill', 'trucker', 'garage', 'strength']; /*Replace Word (Link)*/ var replacelist = ['Job_Center', 'Grand_Exchange', 'Airline_Pilot#ATC_.28Air_Traffic_Control.29', 'Car_Dealer', 'Job_Center', 'Skill_Level_Tokens', 'Trucking', 'Garage', 'Strength']; 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++){ /*Window.element is the Div in which i want to search*/ window.element = document.getElementById("bodyContent"); /*save is the whole HTML code in that Div*/ var save = window.element.innerHTML; /*output is my output Variable and Contains the Whole code with the changed word save.replace searches for the word with a ' ' in front and Behind it and replaces it then with the link and the Text Stays the same*/ /*save.replace(word i search for, replacement word/code*/ var word = ' ' + list[i] + ' '; var reg = new RegExp(word, 'gi'); var output = save.replace(reg, ' ' + '<a href="/wiki/index.php/' + replacelist[i] + '">' + list[i] + '</a>' + ' '); /*Here i overwrite the HTML in the Div with the new code*/ window.element.innerHTML = output; } } else { } } Replace();