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-Background.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 23: Line 23:
 
return;
 
return;
 
}
 
}
requestUrl = "http://en.gfwiki.com/api.php?action=query&titles=File:" + file + ".png&prop=imageinfo&iiprop=url";
+
requestUrl = "http://en.gfwiki.com/api.php?action=query&titles=File:" + file + "&format=json&prop=imageinfo&iiprop=url";
 
var xmlHttp = new XMLHttpRequest();
 
var xmlHttp = new XMLHttpRequest();
 
     xmlHttp.onreadystatechange = function() {  
 
     xmlHttp.onreadystatechange = function() {  

Revision as of 07:57, 20 March 2017

$(document).ready(function() {
	character_element = document.getElementById("background-character");
	generate_bg_element(character_element, "character");
	rarity_element = document.getElementById("background-rarity");
	generate_bg_element(rarity_element, "rarity");
});

function generate_bg_element(bg_element, type) {
	if (bg_element === null) {
		return;
	}
	var style = "";
	var file = "";
	for (var i = 0; i < bg_element.classList.length; i++) {
		var currentClass = bg_element.classList.item(i);
		if (currentClass.startsWith("file=")) {
			file = currentClass.replace("file=", "");
		} else if (currentClass.startsWith("style=")) {
			style = currentClass.replace("style=", "");
		}
	}
	if (file === "") {
		return;
	}
	requestUrl = "http://en.gfwiki.com/api.php?action=query&titles=File:" + file + "&format=json&prop=imageinfo&iiprop=url";
	var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        	response = JSON.parse(xmlHttp.responseText).query.pages;
        	newUrl = response[response.keys[0]].imageinfo.url;
            create_bg_element(newUrl, style, type);
        }
    };
    xmlHttp.open("GET", requestUrl, true); // true for asynchronous 
    xmlHttp.send(null);
}

function create_bg_element(imageUrl, style, type) {
	$("#mw-navigation").append("<img src=\"" + imageUrl + " id=\"bg-" + type + "\" class=\"bg-" + type + " nomobile\" style=\"" + style + "\"/>");
	$("#bg-" + type).fadeIn().css('user-select', 'none');
}