User:Thecyrobot/common.js

//*********************** //* Paint Job Viewer JS * //***********************

window.onload = function{ //Area Damage Link var areaDamageDivs = document.getElementsByClassName("AreaDamage"); for(var n = 0; n < areaDamageDivs.length; n++) { //areaDamageDivs[n].onclick="window.location='https://deeprockgalactic.gamepedia.com/Area_Damage'"; areaDamageDivs[n].setAttribute("onclick","window.open('https://deeprockgalactic.gamepedia.com/Area_Damage', '_blank');"); }   //Skin Viewer var hoverPaintJobJS = document.getElementsByClassName("PaintJob"); var hoverFrameWorkJS = document.getElementsByClassName("FrameWork"); var PaintJob = "Stock"; var FrameWork = ""; var Weapon = document.getElementById("Weapon").className; var WeaponName = document.getElementById("WeaponName").className; var dict = { "stock":"Default", "first":"First Stripe", "deepcore":"Deepcore", "special":"The Company Special", "beyond":"Beyond The Circuit", "dark":"Dark Descent", "desert":"Desert Ranger", "digital":"Digital Danger", "ghostly":"Ghostly Pale", "jungle":"Jungle Raid", "darkfuture":"Dark Future", "megacorp":"Mega Corp", "metallic":"Metallic Vintage", "mint":"Mint Assault", "primal":"Primal Blood", "supporter":"The Supporter", "tool":"Tool Of Destruction", "trusty":"Trusty Rusty", "warmonger":"Warmonger" };   var i;    for (i = 0; i < hoverPaintJobJS.length; i++) { hoverPaintJobJS[i].addEventListener("mousedown", function( event ) {       PaintJob = this.id;        updateSkinViewer;        }, false); hoverPaintJobJS[i].addEventListener("mouseover", function( event ) {       this.className += " Selected"        }, false); hoverPaintJobJS[i].addEventListener("mouseout", function( event ) {       this.className = "PaintJob"        }, false); }   for (i = 0; i < hoverFrameWorkJS.length; i++) { hoverFrameWorkJS[i].addEventListener("mousedown", function( event ) {       FrameWork = this.id;    	updateSkinViewer;        }, false); hoverFrameWorkJS[i].addEventListener("mouseover", function( event ) {   		this.className += " Selected"        }, false); hoverFrameWorkJS[i].addEventListener("mouseout", function( event ) {       this.className = "FrameWork"        }, false); } }

function findImage(fileName) { var api = new mw.Api; api.get( {   action: 'query',    format: 'json',    prop: 'imageinfo',    titles: fileName,    iiprop: 'url', } ).done( function ( data ) {    console.log("Wiki API Query Result:");    console.log(data);//As having them on the same line brakes it, Thanks JS    var url = data.query.pages[Object.keys(data.query.pages)].imageinfo[0].url;    console.log("URL: " + url);    return url; } ); } function updateSkinViewer { console.log("updateSkinViewer Started"); if(FrameWork == null){//Check if stock framework document.getElementById("Name").innerHTML = WeaponName + ": " + Default + " - "+ PaintJob; var url = findImage("File:Skin "+ Weapon + " " + " " + PaintJob +".png"); } else { document.getElementById("Name").innerHTML = WeaponName + ": " + FrameWork + " - "+ PaintJob; var url = findImage("File:Skin "+ Weapon + " " + FrameWork + " " + PaintJob +".png"); }   document.getElementById("Image").innerHTML = url; } //*********** //* MathJax * //*********** //Called in due to Math Extension being ... well completely & utterly broken for >2 months

loadScript("https://polyfill.io/v3/polyfill.min.js?features=es6"); loadScript("https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js");

function loadScript(url) { var script = document.createElement('script'), done = false; script.src = url; script.onload = script.onreadystatechange = function{ if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) { done = true; } };  document.getElementsByTagName("head")[0].appendChild(script); }