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.

MediaWiki:Gadget-Background.js

Welcome to IOP Wiki. This website is maintained by the Girls' Frontline community and is free to edit by anyone.
Revision as of 07:51, 20 March 2017 by ReverseIdeology (talk | contribs)
Jump to navigation Jump to search

Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
$(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://gfwiki.com/api.php?action=query&titles=File:" + file + ".png&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');
}