User:Daric Gaersmith/TES Fan Fiction Collection/promptgenerator.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>
// Declare global variables
var gtxtType = "Place";
var garrTypeGenInfo = new Array();
var gtxtPrompt = "Test";
/*
A hook to load the GUI when the page is loaded.
*/
function onPageLoad() {
loadGUI();
}
/*
Adds HTML content to the current page. This adds the combobox where the user can select a type of prompt, and the
button that begins the generatePrompt() function.
*/
function loadGUI() {
document.getElementById("promptGen_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 Type:<select id=\"typeList\" style=\"float:right; width:75px\"><option></option><option>Item</option><option>Person</option><option>Place</option></select></form></td></tr><tr><td style=\"vertical-align:middle; height:30px;\"><input type=\"button\" id=\"button\" value=\"Generate New Prompt!\" onClick=\"generatePrompt()\"></input></td></tr><tr><td style=\"height:40px;\"><span id=\"printPrompt\">Click the button to generate a prompt!<br></span></td></tr></table>";
}
/*
This function is called when the user clicks the button on the web form.
*/
function generatePrompt(){
gtxtType = document.getElementById("typeList").value;
arrTypeGenInfo = typeGenInfoFunc(gtxtType);
gtxtPrompt = "";
var arrPrompt = new Array();
for(i=0; i<arrTypeGenInfo.length; i++)
{
arrPrompt = document.getElementById(arrTypeGenInfo[i]).innerHTML.split(', ');
gtxtPrompt = gtxtPrompt + arrPrompt[Math.floor( Math.random() * arrPrompt.length)];
}
document.getElementById("printPrompt").innerHTML = "Your prompt is:<br>" + gtxtPrompt;
}
/*
Populates an array from one of the list arrays in User:/Daric_Gaersmith/TES_Fan_Fiction_Collection/Name Generator.
Parameter "txtType" is a string value containing the type of prompt the user has requested.
Returns an array of strings.
*/
function typeGenInfoFunc(txtType) {
var arrReturn = new Array();
switch(txtType)
{
case "Item":
arrReturn = new Array("Items");
break;
case "Person":
arrReturn = new Array("People");
break;
case "Place":
arrReturn= new Array("Places");
break;
}
return arrReturn;
}
addOnloadHook(onPageLoad);
// </nowiki></pre>