MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

/* Recent changes */ if (mw.config.get("wgIsMainPage") === true) { mw.loader.using( ['jquery.spinner'], function {		if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {			if ($("#mp-recent-changes").children.length === 0) {				$("#mp-recent-changes").html($.createSpinner( { size: 'large', type: 'block' } ));			}		} else {			document.addEventListener( 'DOMContentLoaded', function  { if ($("#mp-recent-changes").children.length === 0) { $("#mp-recent-changes").html($.createSpinner( { size: 'large', type: 'block' } )); }			} );		}	});	$.ajax( '/w/api.php?action=parse&page=MediaWiki:RecentChanges.js&prop=wikitext&format=json&maxage=60&smaxage=60&uselang=content', { dataType: 'script', cache: true, dataFilter: function(data, type) {	   return (JSON.parse(data)).parse.wikitext['*'];	}}).fail( function  {		throw new Error( 'Failed to load script' );	}); $.ajax( '/w/api.php?action=parse&page=MediaWiki:RecentChanges.css&prop=wikitext&format=json&maxage=600&smaxage=600&uselang=content', { dataType: 'json', cache: true }).done( function (data) {		mw.loader.addStyleTag(data.parse.wikitext['*']);	}).fail( function {		throw new Error( 'Failed to load css' );	}); }

/* show more template */ function showMore { var toggleButton = document.querySelector(".toggle-content"); if (toggleButton !== null) { var fullTextWrapper = toggleButton.previousElementSibling; fullTextWrapper.classList.add("initial"); fullTextWrapper.classList.add("hidden"); // show toggle button toggleButton.style.display = "table"; // add listener for each button toggleButton.addEventListener("click", function {		  fullTextWrapper = this.previousElementSibling;		  if (fullTextWrapper.classList.contains("initial")) {		    fullTextWrapper.classList.remove("initial");		  }		  // change class if full text is shown/hidden		  if (!fullTextWrapper.classList.contains("hidden")) {		    fullTextWrapper.classList.add("hidden");		  } else {		    fullTextWrapper.classList.remove("hidden");		  }		}); } }

/* generates the colorPalette */ function colorPalette { if (mw.config.get("wgArticleId") === 1625) { var colors = document.querySelectorAll('.color-wrapper .color-row .color-col'); if (colors.length > 0) { for (var i=0; i < colors.length; i++) { colors[i].style.backgroundColor = mw.html.escape(colors[i].dataset.color); var rgb = getComputedStyle(colors[i]).backgroundColor.substr(4).split(")")[0].split(',');				var r = Number.parseInt(rgb[0], 10).toString(16),					g = Number.parseInt(rgb[1], 10).toString(16),					b = Number.parseInt(rgb[2], 10).toString(16);				if (r.length == 1)					r = "0" + r;				if (g.length == 1)					g = "0" + g;				if (b.length == 1)					b = "0" + b;				var span = document.createElement('span');				span.appendChild(document.createElement('br'));				span.appendChild(document.createTextNode("#" + r + g + b));				colors[i].appendChild(span);				var span2 = document.createElement('span');				span2.appendChild(document.createElement('br'));				span2.appendChild(document.createTextNode("#" + r + g + b));				colors[i].appendChild(span2);			}		}	} }

/* mouseover the nodes in the skill trees */ function skillTree { if (mw.config.get("wgArticleId") === 3664) { mw.loader.using( ['oojs-ui-core'] ).then( function {			/*test.get({ action:"query",titles:"File:Connection full.png",prop:"imageinfo",iiprop:"url",iiurlwidth:"48" }).then(data => console.log(data));*/			var i = 0;			var nodes = document.querySelectorAll('.skillTree-tabber.evo-tabber .label-node');			if (nodes.length > 0) {				var mouseover = function(e) {					var node = e.currentTarget;					var name = mw.html.escape(($(node).data('name')).replace(/ /i, " ")+);					var pCost = mw.html.escape($(node).data('cost-primary')+);					var pSpecies = mw.html.escape($(node).data('species-primary')+);					var sCost = mw.html.escape($(node).data('cost-secondary')+);					var sSpecies = mw.html.escape($(node).data('species-secondary')+);					var count = mw.html.escape($(node).data('count')+);					var typeName = mw.html.escape($(node).data('type-name')+);					var type = mw.html.escape($(node).data('type-id')+);					var	fieldset = new OO.ui.FieldsetLayout( { label: typeName + ': ' + name, classes: [ 'container' ] } );					// Add field layouts that contain the form elements to the fieldset. Items can 					// also be specified with the FieldsetLayout's `items` config option: 					fieldset.addItems( [ new OO.ui.FieldLayout( new OO.ui.LabelWidget( { label: 'Cost: ' + pCost + ' ' + pSpecies + ' points' }), {							align: 'left' 						}), ]);					if (sCost !== 'undefined') {						fieldset.addItems( [ new OO.ui.FieldLayout( new OO.ui.LabelWidget( { label: 'and ' + sCost + ' ' + sSpecies + ' points' }), {								align: 'left' 							}), ]);					}					if (count > 1) {						fieldset.addItems( [ new OO.ui.FieldLayout( new OO.ui.LabelWidget( { label: 'Can buy this trait up to ' + count + ' times' }), {								align: 'left' 							}), ]);					}					$(".skillTree-tabber.evo-tabber .description").html(fieldset.$element);				};				for (i=0; i < nodes.length; i++) {					nodes[i].onmouseover = mouseover;				}			}			var tableNodes = document.querySelectorAll('.skillTree-tabber.evo-tabber .label-table');			for (i=0; i < tableNodes.length; i++) {				var typeNodes = tableNodes[i].querySelectorAll('.label-node');				var tableSpecies = mw.html.escape($(tableNodes[i]).data('species-primary')+);				var speciesCosts = {};				for (var y=0; y < typeNodes.length; y++) {					var pCost = mw.html.escape($(typeNodes[y]).data('cost-primary')+);					var pSpecies = mw.html.escape($(typeNodes[y]).data('species-primary')+);					var sCost = mw.html.escape($(typeNodes[y]).data('cost-secondary')+);					var sSpecies = mw.html.escape($(typeNodes[y]).data('species-secondary')+);					var count = mw.html.escape($(typeNodes[y]).data('count')+); if (typeof speciesCosts[pSpecies] === 'undefined') { speciesCosts[pSpecies] = 0; }					speciesCosts[pSpecies] += pCost * count; if (sCost !== 'undefined') { if (typeof speciesCosts[sSpecies] === 'undefined') { speciesCosts[sSpecies] = 0; }						speciesCosts[sSpecies] += sCost * count; }				}				for (const specieCost in speciesCosts) { if (speciesCosts.hasOwnProperty(specieCost)) { document.querySelectorAll(".skillTree-tabber.evo-tabber .total-tree-"+tableSpecies)[0].textContent += specieCost + ": " + speciesCosts[specieCost] + " "; }				}			}		});	} }

//Allow setting all Tabber's tab based on a preset "open-tab=XX" data function selectTab { var tabber = document.getElementsByClassName("tabber-NavSpecies"); if (tabber.length > 0) { mw.loader.using('ext.tabberNeue', function {   		var openTab = function(container, tabber) {    			var number = parseInt(mw.html.escape(container.getAttribute('data-open-tab')),10);                var tabElem = tabber.children[0].getElementsByTagName("nav")[0].getElementsByTagName("a")[number];                if (!tabElem.classList.contains("tabber__tab--active")) {                	tabElem.click;                }    		};    		for (var tab = 0; tab < tabber.length; tab++) {	            if (tabber[tab].getAttribute('data-open-tab').length > 0) {	            	if (tabber[tab].children[0].classList.contains("tabber--live")) {		                openTab(tabber[tab], tabber[tab].children[0]);	            	} else {	            		var observer = new MutationObserver(function(mutations, observer) { mutations.forEach(function(mutation) {							   if (mutation.target.classList.contains("tabber--live")) {									openTab(mutation.target.parentNode, mutation.target);					                observer.disconnect;		            			}							}); });						var config = { attributes: true, attributeFilter: ["class"] };						observer.observe(tabber[tab].children[0], config);	           	}	            }	        }    	}); } }

if ( document.readyState === 'interactive' || document.readyState === 'complete' ) { selectTab; showMore; colorPalette; skillTree; } else { document.addEventListener( 'DOMContentLoaded', function {		selectTab;		showMore;		colorPalette;		skillTree;	} ); }