MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Pianoforte (talk | contribs) Created page with "→Any JavaScript here will be loaded for all users on every page load.: $(document).ready(function() { build_skill_form(); }); function build_skill_form() {..." |
Pianoforte (talk | contribs) mNo edit summary |
||
Line 9: | Line 9: | ||
calculator_element = document.getElementById("skill_calculator"); | calculator_element = document.getElementById("skill_calculator"); | ||
calculator_element.outerHTML = | calculator_element.outerHTML = | ||
'<div id="skill_calculator"><table style=" | '<div id="skill_calculator"><table style="cellspacing="5"><tr>' + | ||
'< | '<td rowspan="2" style="background:rgba(128, 128, 128, 0);width:52px;height:52px"></td>' + | ||
'<th colspan="2" style="background:rgba(128, 128, 128, 0.5)">dummy</td>' + | |||
'<th colspan=" | |||
'</tr><tr>' + | '</tr><tr>' + | ||
'< | '<td><select style=“background:rgba(255, 182, 0, 1);color:rgba(128, 128, 128, 1);width:50px;text-align:center" id="skill_level" onchange="display_data()">' + | ||
'<option value="0"> | '<option value="0">Lv. 1</option>' + | ||
'<option value="1"> | '<option value="1">Lv. 2</option>' + | ||
'<option value="2"> | '<option value="2">Lv. 3</option>' + | ||
'<option value="3"> | '<option value="3">Lv. 4</option>' + | ||
'<option value="4"> | '<option value="4">Lv. 5</option>' + | ||
'<option value="5"> | '<option value="5">Lv. 6</option>' + | ||
'<option value="6"> | '<option value="6">Lv. 7</option>' + | ||
'<option value="7"> | '<option value="7">Lv. 8</option>' + | ||
'<option value="8"> | '<option value="8">Lv. 9</option>' + | ||
'<option value="9"> | '<option value="9">Lv. 10</option>' + | ||
'</select></ | '</select></td></tr></table><div id="activation"></div></div>'; | ||
display_data(); | display_data(); | ||
} | } |
Revision as of 03:51, 31 August 2016
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() {
build_skill_form();
});
function build_skill_form() {
if (skill_data[mw.config.get("wgPageName")]) {
calculator_element = document.getElementById("skill_calculator");
calculator_element.outerHTML =
'<div id="skill_calculator"><table style="cellspacing="5"><tr>' +
'<td rowspan="2" style="background:rgba(128, 128, 128, 0);width:52px;height:52px"></td>' +
'<th colspan="2" style="background:rgba(128, 128, 128, 0.5)">dummy</td>' +
'</tr><tr>' +
'<td><select style=“background:rgba(255, 182, 0, 1);color:rgba(128, 128, 128, 1);width:50px;text-align:center" id="skill_level" onchange="display_data()">' +
'<option value="0">Lv. 1</option>' +
'<option value="1">Lv. 2</option>' +
'<option value="2">Lv. 3</option>' +
'<option value="3">Lv. 4</option>' +
'<option value="4">Lv. 5</option>' +
'<option value="5">Lv. 6</option>' +
'<option value="6">Lv. 7</option>' +
'<option value="7">Lv. 8</option>' +
'<option value="8">Lv. 9</option>' +
'<option value="9">Lv. 10</option>' +
'</select></td></tr></table><div id="activation"></div></div>';
display_data();
}
}
function display_data() {
data = skill_data[mw.config.get("wgPageName")];
if (data !== null) {
index = document.getElementById("skill_level").value;
regex = /\(\$\w+\)/g;
formatted_text = data.text;
vars = data.text.match(regex);
for (i = 0; i < vars.length; i++) {
var_name = vars[i].substring(2, vars[i].length - 1);
formatted_text = formatted_text.replace(
vars[i],
data[var_name][index]);
}
document.getElementById("activation").outerHTML =
'<th id="activation">' + data.activation[index] + '</th>';
document.getElementById("description").outerHTML =
'<th id="description">' + formatted_text + '</th>';
}
}
skill_data = {
'Kar98k': {
text: "After taking aim for 2 seconds, shoot the nearest target for ($damage_value) the damage.",
activation: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
damage_value: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
time: [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9],
},
};