helialprofile.png
Welcome to IOPWiki, Commander.
We are lacking editors focused on Girls' Frontline and Girls' Frontline 2. You can contribute without an account. Learn how to contribute and join our Discord server.

Difference between revisions of "MediaWiki:Gadget-SkillForm.js"

Welcome to IOP Wiki. This website is maintained by the Girls' Frontline community and is free to edit by anyone.
Jump to navigation Jump to search
Line 16: Line 16:
 
function build_skill_form() {
 
function build_skill_form() {
 
     skill_data = get_skill_data();
 
     skill_data = get_skill_data();
     if (skill_data) {
+
     if (skill_data[mw.config.get("wgPageName")]) {
 
         calculator_element = document.getElementById("skill_calculator");
 
         calculator_element = document.getElementById("skill_calculator");
 
         calculator_element.outerHTML =
 
         calculator_element.outerHTML =
Line 36: Line 36:
 
                 '</select></td><td id="cooldown"></td></tr><tr></tr></table><p id="description"></p></div>';
 
                 '</select></td><td id="cooldown"></td></tr><tr></tr></table><p id="description"></p></div>';
 
         document.getElementById("skill_level").onchange = display_data;
 
         document.getElementById("skill_level").onchange = display_data;
         data = skill_data[mw.config.get("wgPageName")];
+
         display_data();
        if (data === null) {
+
    }
        data = skill_data;
+
}
 +
 +
function display_data() {
 +
    skill_data = get_skill_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]);
 
         }
 
         }
    if (data !== null) {
+
        if (data.hasOwnProperty('cooldown')) {
        index = document.getElementById("skill_level").value;
+
        cooldownText = '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">' + data.cooldown[index] + 's cooldown';
        regex = /\(\$\w+\)/g;
+
        if (data.hasOwnProperty('initial')) {
        formatted_text = data.text;
+
        cooldownText += ', ' + data.initial + 's initial cooldown';
        vars = data.text.match(regex);
+
        }
        for (i = 0; i < vars.length; i++) {
+
        cooldownText += '</td>';
            var_name = vars[i].substring(2, vars[i].length - 1);
+
        document.getElementById("cooldown").outerHTML = cooldownText;
            formatted_text = formatted_text.replace(
+
        } else if (data.hasOwnProperty('activation')) {
                vars[i],
+
        document.getElementById("cooldown").outerHTML =
                data[var_name][index]);
+
            '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">' + data.activation[index] + '% chance to activate</td>';
        }
+
        } else {
        if (data.hasOwnProperty('cooldown')) {
+
        document.getElementById("cooldown").outerHTML =
        cooldownText = '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">' + data.cooldown[index] + 's cooldown';
+
            '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">Passive</td>';
        if (data.hasOwnProperty('initial')) {
+
        }
        cooldownText += ', ' + data.initial + 's initial cooldown';
+
        document.getElementById("description").outerHTML =
        }
+
            '<p id="description">' + formatted_text + '</p>';
        cooldownText += '</td>';
 
        document.getElementById("cooldown").outerHTML = cooldownText;
 
        } else if (data.hasOwnProperty('activation')) {
 
        document.getElementById("cooldown").outerHTML =
 
            '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">' + data.activation[index] + '% chance to activate</td>';
 
        } else {
 
        document.getElementById("cooldown").outerHTML =
 
            '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">Passive</td>';
 
        }
 
        document.getElementById("description").outerHTML =
 
            '<p id="description">' + formatted_text + '</p>';
 
    }
 
 
     }
 
     }
 
}
 
}

Revision as of 06:54, 7 April 2017

// Please refer to MediaWiki:SkillData.js to add skill data for new T-Doll pages.
$(document).ready(function() {
	$.getScript("http://gfwiki.com/index.php?title=" + mw.config.get("wgPageName") + "/skilldata&action=raw&ctype=text/javascript", function( data, textStatus, jqxhr ) {
		if (typeof get_skill_data !== 'undefined') {
			build_skill_form();
		} else {
			$.getScript( "http://gfwiki.com/index.php?title=MediaWiki:SkillData.js&action=raw&ctype=text/javascript", function( inner_data, inner_textStatus, inner_jqxhr ) {
				build_skill_form();
			});
		}
	});
});

var SkillData = {};

function build_skill_form() {
    skill_data = get_skill_data();
    if (skill_data[mw.config.get("wgPageName")]) {
        calculator_element = document.getElementById("skill_calculator");
        calculator_element.outerHTML =
            '<div id="skill_calculator" style="position:absolute"><table cellspacing="5"><tr>' +
                '<td rowspan="2" style="background:rgba(128, 128, 128, 0);width:52px;height:52px"></td>' +
                '<td colspan="2" style="background:rgba(255, 255, 255, 0.25);min-width: 300px;">&#8199;</td>' +
            '</tr><tr>' +
                '<td style="width:60px"><select class="skill" id="skill_level" onchange="SkillData.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" selected="selected">Lv. 10</option>' +
                '</select></td><td id="cooldown"></td></tr><tr></tr></table><p id="description"></p></div>';
        document.getElementById("skill_level").onchange = display_data;
        display_data();
    }
}
 
function display_data() {
    skill_data = get_skill_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]);
        }
        if (data.hasOwnProperty('cooldown')) {
        	cooldownText = '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">' + data.cooldown[index] + 's cooldown';
        	if (data.hasOwnProperty('initial')) {
        		cooldownText += ', ' + data.initial + 's initial cooldown';
        	}
        	cooldownText += '</td>';
	        document.getElementById("cooldown").outerHTML = cooldownText;
        } else if (data.hasOwnProperty('activation')) {
	        document.getElementById("cooldown").outerHTML =
	            '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">' + data.activation[index] + '% chance to activate</td>';
        } else {
        	document.getElementById("cooldown").outerHTML =
	            '<td id="cooldown" style="color:rgba(255, 182, 0, 1)">Passive</td>';
        }
        document.getElementById("description").outerHTML =
            '<p id="description">' + formatted_text + '</p>';
    }
}