tanksmith.io custom unit menu

read the title

Versione datata 18/02/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        tanksmith.io custom unit menu
// @namespace   http://bzzzzdzzzz.blogspot.com/
// @description read the title
// @author      BZZZZ
// @include     /^https?\:\/\/(www\.)?tanksmith\.io\/([?#]|$)/
// @version     0.11
// @grant       none
// @run-at      document-end
// @inject-into content
// ==/UserScript==
 
{
const a=document.createElement("div");
a.setAttribute("onclick",`"use strict";
	document.head.insertAdjacentHTML("beforeend","<style>#store>div{display:none;}</style>");
	const mnames=["Wood","Iron","Gold","Diamond","Amethyst"],unames=["Basic\\xA0Unit","Basic\\xA0Turret","Sniper\\xA0Turret","Twin\\xA0Turret","Cannon\\xA0Turret","Healing\\xA0Unit","Alchemy\\xA0Lab","Booster\\xA0Unit","Octa\\xA0Turret","Spike"],ucost=[6,8,10,10,18,14,20,12,16,8],store=document.getElementById("store");
	const mselectedcolor="#00FF00",munselectedcolor="#FFFF00",textcolor="#000000",cursor="pointer",mselect=function(){
		mselected.style.backgroundColor=munselectedcolor;
		mselected=this;
		this.style.backgroundColor=mselectedcolor;
	},uselect=function(){
		document.getElementById("u:1;0").onclick.call({"id":\`u:\${this.dataset.id};\${mselected.dataset.id}\`});
	},setcostdisplay=function(){
		const m=parseInt(mselected.dataset.id);
		costdisplay.textContent=\`\${(1+m)*ucost[parseInt(this.dataset.id)-1]} \${mnames[m]}\`;
	},clearcostdisplay=()=>costdisplay.textContent="";
	let mselected=document.createElement("span");
	mselected.style.backgroundColor=mselectedcolor;
	mselected.style.color=textcolor;
	mselected.style.cursor=cursor;
	mselected.textContent=mnames[0];
	mselected.onclick=mselect;
	mselected.dataset.id="0";
	store.appendChild(mselected);
	let i=1,span;
	while(i<5){
		store.appendChild(document.createTextNode(" "));
		span=document.createElement("span");
		span.style.backgroundColor=munselectedcolor;
		span.style.color=textcolor;
		span.style.cursor=cursor;
		span.textContent=mnames[i];
		span.onclick=mselect;
		span.dataset.id=i++;
		store.appendChild(span);
	}
	store.appendChild(document.createElement("hr"));
	span=document.createElement("span");
	span.style.backgroundColor=munselectedcolor;
	span.style.color=textcolor;
	span.style.cursor=cursor;
	span.textContent=unames[0];
	span.onclick=uselect;
	span.onmouseenter=setcostdisplay;
	span.onmouseleave=clearcostdisplay;
	span.dataset.id="1";
	store.appendChild(span);
	i=1;
	while(i<10)if(i===7/*booster unit*/)i++;else{
		store.appendChild(document.createTextNode(" "));
		span=document.createElement("span");
		span.style.backgroundColor=munselectedcolor;
		span.style.color=textcolor;
		span.style.cursor=cursor;
		span.textContent=unames[i++];
		span.onclick=uselect;
		span.onmouseenter=setcostdisplay;
		span.onmouseleave=clearcostdisplay;
		span.dataset.id=i;
		store.appendChild(span);
	}
	store.appendChild(document.createElement("hr"));
	const costdisplay=document.createElement("span");
	costdisplay.style.color="#FFFFFF";
	store.appendChild(costdisplay);`);
a.click();
}