MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After publishing, 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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
if ( mw.config.get( 'wgPageName' ) === "Module:Crafting_DB" ) {
document.getElementById('craftingModuleContainer').innerHTML = '<table class="craftingModuleTable">\
<tr>\
<th>Craftable Name</th>\
<td><input type="text" id="craftableName"></td>\
</tr>\
<tr>\
<th>A1</th>\
<td><input type="text" id="a1Ingredient"></td>\
</tr>\
<tr>\
<th>B1</th>\
<td><input type="text" id="b1Ingredient"></td>\
</tr>\
<tr>\
<th>C1</th>\
<td><input type="text" id="c1Ingredient"></td>\
</tr>\
<tr>\
<th>A2</th>\
<td><input type="text" id="a2Ingredient"></td>\
</tr>\
<tr>\
<th>B2</th>\
<td><input type="text" id="b2Ingredient"></td>\
</tr>\
<tr>\
<th>C2</th>\
<td><input type="text" id="c2Ingredient"></td>\
</tr>\
<tr>\
<th>A3</th>\
<td><input type="text" id="a3Ingredient"></td>\
</tr>\
<tr>\
<th>B3</th>\
<td><input type="text" id="b3Ingredient"></td>\
</tr>\
<tr>\
<th>C3</th>\
<td><input type="text" id="c3Ingredient"></td>\
</tr>\
<tr>\
<th>Image Name</th>\
<td><input type="text" id="outputImageName"></td>\
</tr>\
<tr>\
<th>Ingredient List</th>\
<td><input type="text" id="craftingIngredientList"></td>\
</tr>\
<tr>\
<th>Shapless</th>\
<td><input type="checkbox" id="craftingIsShapless"></td>\
</tr>\
<tr>\
<th>Description</th>\
<td><input type="text" id="craftingDescription"></td>\
</tr>\
</table>\
<div class="craftingButtons">\
<button onclick="cleanCraftingCode()">CLEAN</button>\
<button onclick="replaceCraftingCode()">REPLACE</button>\
<button onclick="addCraftingCode()">ADD</button>\
</div>';
}
function cleanCraftingCode() {
document.getElementById('craftableName').value = "";
document.getElementById('a1Ingredient').value = "";
document.getElementById('b1Ingredient').value = "";
document.getElementById('c1Ingredient').value = "";
document.getElementById('a2Ingredient').value = "";
document.getElementById('b2Ingredient').value = "";
document.getElementById('c2Ingredient').value = "";
document.getElementById('a3Ingredient').value = "";
document.getElementById('b3Ingredient').value = "";
document.getElementById('c3Ingredient').value = "";
document.getElementById('outputImageName').value = "";
document.getElementById('craftingIngredientList').value = "";
document.getElementById('craftingIsShapless').checked = false;
document.getElementById('craftingDescription').value = "";
}
function newCraftingCode() {
var craftableString = "";
var craftableName = document.getElementById('craftableName').value;
var craftingIngredient1 = document.getElementById('a1Ingredient').value;
var craftingIngredient2 = document.getElementById('b1Ingredient').value;
var craftingIngredient3 = document.getElementById('c1Ingredient').value;
var craftingIngredient4 = document.getElementById('a2Ingredient').value;
var craftingIngredient5 = document.getElementById('b2Ingredient').value;
var craftingIngredient6 = document.getElementById('c2Ingredient').value;
var craftingIngredient7 = document.getElementById('a3Ingredient').value;
var craftingIngredient8 = document.getElementById('b3Ingredient').value;
var craftingIngredient9 = document.getElementById('c3Ingredient').value;
var craftingIngredients = [craftingIngredient1, craftingIngredient2, craftingIngredient3, craftingIngredient4, craftingIngredient5, craftingIngredient6, craftingIngredient7, craftingIngredient8, craftingIngredient9];
var outputImageName = document.getElementById('outputImageName').value;
var craftingIngredientList = document.getElementById('craftingIngredientList').value;
var craftingIsShapless = document.getElementById('craftingIsShapless').checked;
var craftingDescription = document.getElementById('craftingDescription').value;
craftableString += '{"' + craftableName + '",{'
for (var i = 0; i < 9; i++) {
if (craftingIngredients[i].includes(';')) {
var ingredient = craftingIngredients[i].split(";").map(function(i){return '"' + i + '"'}).join()
craftableString += '{' + ingredient + '},'
} else if (craftingIngredients[i].includes(',')) {
var ingredient = craftingIngredients[i].split(",").map(function(i){return '"' + i + '"'}).join()
craftableString += '{' + ingredient + '},'
} else {
craftableString += '"' + craftingIngredients[i] + '",'
}
}
craftableString += '},"' + outputImageName + '","' + craftingIngredientList + '",' + craftingIsShapless + ',"' + craftingDescription + '"},'
return craftableString;
}
function replaceCraftingCode() {
document.getElementById('generatedCraftingCode').innerText = newCraftingCode() + "\n";
}
function addCraftingCode() {
document.getElementById('generatedCraftingCode').innerText += newCraftingCode() + "\n";
}