User:Jak Atackka/namegenerator.js
The UESPWiki – Your source for The Elder Scrolls since 1995
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// <pre><nowiki>
var race = "Nord";
var gender = "Male";
var meta = "NoHyphen";
var raceGenInfo = new Array();
var name = "Test";
function onPageLoad() {
loadGUI();
}
function loadGUI() {
document.getElementById("nameGen_allContent").innerHTML = "<table cellpadding=0 cellspacing=0 style=\"width:100%; background-color:inherit; font-family:Arial; font-size:10pt; text-align:center;\"><tr><td style=\"text-align:left;\"><form>Select Race:<select id=\"raceList\" onchange=\"updateOptions()\" style=\"float:right; width:75px\"><option></option><option>Bosmer</option><option>Breton</option><option>Nord</option></select><div style=\"height:10px;\"></div>Select Gender:<select id=\"genderList\" style=\"float:right; width:75px;\"><option></option><option>Male</option><option>Female</option></select><div style=\"height:10px;\"></div><span id=\"GUIoptions\"></span></form></td></tr><tr><td style=\"vertical-align:middle; height:30px;\"><input type=\"button\" id=\"button\" value=\"Generate New Name!\" onClick=\"generateName()\"></input></td></tr><tr><td style=\"height:40px;\"><span id=\"printName\">Click the button to generate a name!<br></span></td></tr></table>";
}
function generateName() {
race = document.getElementById("raceList").value;
gender = document.getElementById("genderList").value;
meta = metaFunc(race);
raceGenInfo = raceGenInfoFunc(race, gender, meta);
name = "";
var nameArr = new Array();
for(i=0; i<raceGenInfo[0].length; i++) {
nameArr = document.getElementById(raceGenInfo[0][i]).innerHTML.split(', ');
name = name + nameArr[Math.floor( Math.random() * nameArr.length)];
}
if(raceGenInfo[1][0] != "None") {
name = name + " ";
for(i=0; i<raceGenInfo[1].length; i++) {
nameArr = document.getElementById(raceGenInfo[1][i]).innerHTML.split(', ');
if( meta == "Hyphen" ) {
name = name + capitalize(nameArr[Math.floor( Math.random() * nameArr.length)]);
} else {
name = name + nameArr[Math.floor( Math.random() * nameArr.length)];
}
}
}
document.getElementById("printName").innerHTML = "Your " + gender + " " + race + " name is:<br>" + name;
}
function raceGenInfoFunc(race, gender, meta) {
/* raceGenInfo is an array that contains data on each race. The variables are as follows:
0: Array() of links to each array for the FIRST name. Some races, such as Argonians, have a variable number of syllables for their names.
1: Array() of links to each array for the LAST name. Some races have no last name - in this case, array[1] = "None";
This only returns the IDs of the associated arrays, not the entire array. The actual choosing of the name is done later.
*/
var returnArray = new Array(new Array(), new Array());
switch(race) {
case "Bosmer":
var subArray = new Array();
subArray[0] = "BosmerName" + gender + "1";
for( i = 0; i < (meta - 2); i++) { subArray[i+1] = "BosmerName" + gender + "2"; }
subArray[meta-1] = "BosmerName" + gender + "3";
returnArray[0] = subArray;
returnArray[1] = new Array("None");
break;
case "Breton":
returnArray[0] = new Array("BretonFirstName" + gender + "1", "BretonFirstName" + gender + "2");
returnArray[1] = new Array("BretonLastName1", "BretonLastName2");
break;
case "Nord":
returnArray[0] = new Array("NordFirstName" + gender + "1", "NordFirstName" + gender + "2");
returnArray[1] = new Array("NordLastName1", meta, "NordLastName2");
break;
}
return returnArray;
}
function metaFunc(race) {
var returnVar = "None";
switch(race) {
case "Bosmer":
returnVar = document.getElementById("metaSlider").value;
break;
case "Nord":
if(document.getElementById("metaBox").checked == true) { returnVar = "Hyphen"; }
else { returnVar = "NoHyphen"; }
break;
}
return returnVar;
}
function capitalize(str) {
return str.substr(0,1).toUpperCase() + str.substr(1).toLowerCase();
}
function updateOptions() {
switch(document.getElementById("raceList").value) {
case "Bosmer":
document.getElementById("GUIoptions").innerHTML = "Syllables: <span id=\"metaInfo\">3</span><span style=\"float:right;\"><input id=\"metaSlider\" type=\"range\" min=\"2\" max=\"4\" value=\"3\" onchange=\"updateMetaInfo(this.value)\" style=\" width:70px\"></input></span>";
break;
case "Breton":
document.getElementById("GUIoptions").innerHTML = "<br><div style=\"text-align: center;\">This race isn't complete yet. Sorry!</div>";
break;
case "Nord":
document.getElementById("GUIoptions").innerHTML = "Hyphenated Last Name <span style=\"float:right;\"><input id=\"metaBox\" type=\"Checkbox\" checked=\"true\"></input></span>";
break;
default:
document.getElementById("GUIoptions").innerHTML = "";
break;
}
}
function updateMetaInfo(variable) {
document.getElementById("metaInfo").innerHTML = variable;
}
addOnloadHook(onPageLoad);
// </nowiki></pre>