MediaWiki:SkillTools.js

/* Skill Template Tools version 0.5alpha, an extension module of MediaWiki:TemplateTools.js. * Depends on MediaWiki:SkillToolsOptions.js and MediaWiki:SkillToolsChanges.js. * Licensed under BY-NC-SA 2.0 only. * An alternate GDFL licensed version is available elsewhere. * */

document.write(' '); document.write(' ');

/*

openSkillToolBox
*/

function openSkillToolBox{ var toolBox = document.getElementById('skill_tool_box'); if (!toolBox) { createSkillToolBox; } else { toolBox.style.display='block'; }	document.getElementById('templateToolsDiv').style.display='none'; }

/*

createSkillToolBox
*/

function createSkillToolBox{ var toolsDiv = document.createElement("div"); toolsDiv.style.border='1px solid black'; toolsDiv.id = 'skill_tools'; toolsDiv.style.clear='both'; toolsDiv.innerHTML = '\n' + 'Skill Template Tools version 0.5alpha  report a bug \n' + 'Return to main menu \n' + ' \n' + ' \n' + ' Desc=  ' + ' \n' + ' Unparsed:  ' + ' Template)" onClick="fillOutSkillTemplate"/>\n' + ' Form)" onClick="extractSkillTemplate"/>\n' + ' \n'; var editBuffer = document.getElementById("editform"); editBuffer.parentNode.insertBefore(toolsDiv, editBuffer); extractSkillTemplate; }

/*

extractSkillTemplate
*/ /* The following function assumes the entire list of parameters for * {{Skill box {{{1|}}} resides in its own article. If it is within * some other article, such is the case with most other types of info * box templates (beastinfo, weapons, locations etc), then additional * extraction is needed. See *     http://guildwars.wikia.com/wiki/MediaWiki:SkillTools.js  * for an example. */ function extractSkillTemplate{ var input = document.editform.wpTextbox1.value;

if(input.search(/\{\{Skill box \{\{\{1\|\}\}\}/i)!= -1) { openSkillToolBox; parseSkillTemplate(input); return true; }	return false; } /*

fillOutSkillTemplate
*/ function fillOutSkillTemplate{ var toolBox = document.getElementById('skill_tool_box'); var output = '{{Skill box {{{1|}}}|\n\t' + 'name=' + toolBox.SkillNameEn.value + '|\n\t' + 'campaign=' + toolBox.CampaignSel.value + '|\n\t' + 'profession=' + toolBox.ProfessionSel.value + '|\n\t' + 'attribute=' + toolBox.AttributeSel.value + '|\n\t' + 'type=' + toolBox.SkillTypeSel.value + '|\n\t'; if (toolBox.eliteness.checked){ output = output + 'elite=yes|\n\t'; } 	if (toolBox.costSel.value){ output = output + toolBox.costSel.value + '=' + toolBox.costNum.value + '|\n\t'; }	if (toolBox.castTime.value){ output = output	+ 'activation=' + toolBox.castTime.value + '|\n\t' }	if (toolBox.rechargeNum.value && toolBox.rechargeNum.value != 0){ output = output	+ 'recharge=' + toolBox.rechargeNum.value + '|\n\t' }	switch (toolBox.miscSel.value){ case 'exhaustion': toolBox.miscNum.value = 'yes'; case 'upkeep': case 'sacrifice': output = output + toolBox.miscSel.value + '=' + toolBox.miscNum.value + '|\n\t'; default: }	output = output + 'description=' + toolBox.descText.value + '|\n\t'

switch (toolBox.effectCountSel.value){ case '4': output = output + 'progression_3_effect=' + toolBox.effect4_partial.value + toolBox.effect4Sel.value + toolBox.effect4_other.value + '|progression_3_0=' + toolBox.effect4_0.value + '|progression_3_15=' + toolBox.effect4_15.value + '|\n'; case '3': output = output + 'progression_2_effect=' + toolBox.effect3_partial.value + toolBox.effect3Sel.value + toolBox.effect3_other.value + '|progression_2_0=' + toolBox.effect3_0.value + '|progression_2_15=' + toolBox.effect3_15.value + '|\n'; case '2': output = output + 'progression_1_effect=' + toolBox.effect2_partial.value + toolBox.effect2Sel.value + toolBox.effect2_other.value + '|progression_1_0=' + toolBox.effect2_0.value + '|progression_1_15=' + toolBox.effect2_15.value + '|\n'; case '1': output = output + 'progression_0_effect=' + toolBox.effect1_partial.value + toolBox.effect1Sel.value + toolBox.effect1_other.value + '|progression_0_0=' + toolBox.effect1_0.value + '|progression_0_15=' + toolBox.effect1_15.value + '|\n'; default: output = output + toolBox.unparsedText.value + '}}\n'; }	document.editform.wpTextbox1.value = output; } /*

parseSkillTemplate(input)
*/ function parseSkillTemplate(input){ var toolBox = document.getElementById('skill_tool_box');

var trimmed = input.replace(/\{\{Skill box/i,).replace(/\{\{\{1\|\}\}\}/,); trimmed = trimmed.replace(/\t/g,'').replace(/\n/g,'|').replace(/ /g,' '); trimmed = trimmed.replace(/ \|/g,'|').replace(/\| /g,'|').replace(/\|\|/g,'|'); var assignments = trimmed.split('|');

/* Merges piped links and templates that got split, by pre-pending the front to the back. */	for (var i=0; i < assignments.length-1; i++){ var myAssign = 	assignments[i]; if ((myAssign.lastIndexOf() > myAssign.lastIndexOf()) 		 ||(myAssign.lastIndexOf(''))){ assignments[i+1] = myAssign + '|' + assignments[i+1]; assignments[i] = '' }	}

toolBox.SkillNameEn.value = extractParameter('name', assignments); toolBox.CampaignSel.value = extractParameter('campaign', assignments); toolBox.ProfessionSel.value = extractParameter('profession', assignments); profChange; toolBox.AttributeSel.value = extractParameter('attribute', assignments); toolBox.SkillTypeSel.value = extractParameter('type', assignments); if (extractParameter('elite', assignments) == 'yes'){ toolBox.eliteness.checked = true; eliteChange; }	if (extractParameter('quest', assignments) == 'yes'){ toolBox.questability.checked = true; questChange; }

var val1 = extractParameter('energy', assignments); if (val1){ toolBox.costSel.value = 'energy'; costChange toolBox.costNum.value = val1; } else { val1 = extractParameter('adrenaline', assignments); if (val1){ toolBox.costSel.value = 'adrenaline'; costChange toolBox.costNum.value = val1; } else { toolBox.costSel.value = ''; }	}

var val2 = extractParameter('activation', assignments); switch (val2){ case '1⁄4': val2 = '¼'; break; case '1⁄2': val2 = '½'; break; case '3⁄4': val2 = '¾'; break; default: }	toolBox.castTime.value = val2;

toolBox.rechargeNum.value = extractParameter('recharge', assignments);

var val0 = extractParameter('upkeep', assignments); if (val0){ toolBox.miscSel.value = 'upkeep'; miscChange toolBox.miscNum.value = val0; } else { val0 = extractParameter('sacrifice', assignments); if (val0){ toolBox.miscSel.value = 'sacrifice'; miscChange toolBox.miscNum.value = val0; } else { val0 = extractParameter('exhaustion', assignments); if (val0 == 'yes' ){ toolBox.miscSel.value = 'exhaustion'; miscChange toolBox.miscNum.value = val0; } else { toolBox.miscSel.value = ''; }		}	}

toolBox.descText.innerHTML = extractParameter('description', assignments);

var eff4 = extractParameter('progression_3_effect', assignments); var eff3 = extractParameter('progression_2_effect', assignments); var eff2 = extractParameter('progression_1_effect', assignments); var eff1 = extractParameter('progression_0_effect', assignments); var effCount = 0; if (eff4){ effCount = 4; } else if (eff3){ effCount = 3; } else if (eff2){ effCount = 2; } else if (eff1){ effCount = 1; } 	toolBox.effectCountSel.value = effCount; effectCountChange switch (effCount){ case 4: toolBox.effect4_other.value = eff4; toolBox.effect4_0.value = extractParameter('progression_3_0', assignments); toolBox.effect4_15.value = extractParameter('progression_3_15', assignments); case 3: toolBox.effect3_other.value = eff3; toolBox.effect3_0.value = extractParameter('progression_2_0', assignments); toolBox.effect3_15.value = extractParameter('progression_2_15', assignments); case 2: toolBox.effect2_other.value = eff2; toolBox.effect2_0.value = extractParameter('progression_1_0', assignments); toolBox.effect2_15.value = extractParameter('progression_1_15', assignments); case 1: toolBox.effect1_other.value = eff1; toolBox.effect1_0.value = extractParameter('progression_0_0', assignments); toolBox.effect1_15.value = extractParameter('progression_0_15', assignments); default: }	var unparsed = ''; for (var j=0; j < assignments.length; j++){ var assignTrimmed = trimString(assignments[j]); if (assignments[j].indexOf('=') != -1){ unparsed = unparsed + '\t' + assignments[j] + '|\n'; }	}	toolBox.unparsedText.value = unparsed; }

/* */