Userscripts/Crew Info Deployed

```
// ==UserScript==
// @name DS - Crew Info Deployed Script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Thurston
// @match https://command.drop-shock.com/map\_index.html
// @match http://command.drop-shock.com/map\_index.html
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant none
// ==/UserScript==
/\* globals jQuery, $, waitForKeyElements \*/

(function() {
 'use strict';

 setTimeout(function() {
 let divs = window.frames[2].document.getElementsByTagName("div");

 var unitArray = [];

 for (let i = 0; i < divs.length; i++) {

 let id = divs[i].getAttribute("id");

 if (id === null) {
 continue;
 }

 if (id.includes("unit")) {
 unitArray.push(divs[i]);
 }
 }

 let br = document.createElement("br"); // Break
 let p = document.createElement("img"); // Piloting
 let g = document.createElement("img"); // Gunnery

 let m1 = document.createElement("img"); // Merit 1
 let m2 = document.createElement("img"); // Merit 2
 let m3 = document.createElement("img"); // Merit 3

 let sIcon = document.createElement("img"); // Shield Icon
 let aIcon = document.createElement("img"); // Armor Icon

 let s = document.createElement("span"); // Shield
 let a = document.createElement("span"); // Armor

 m1.setAttribute("id", "meritthurston-1");
 m2.setAttribute("id", "meritthurston-2");
 m3.setAttribute("id", "meritthurston-3");

 sIcon.setAttribute("id", "sicon");
 aIcon.setAttribute("id", "aicon");

 s.setAttribute("class", "helptextb");
 a.setAttribute("class", "helptextb");

 unitArray.forEach(function(value, key) {
 if (value === undefined || value === null) return;
 window.frames[2].document.getElementById(value.getAttribute("id")).addEventListener("click", function() {
 var url="/panel\_unitinfo.php?unit=" + value.getAttribute("data-id");

 $.get(url, function(data, status){
 if (status === "success") {
 let gpIcons = $(data).filter("#crew1DIV").find("img");
 let meritIcons = $(data).filter("#crewmerits1DIV").find("img");
 let unitData = $(data).filter("#unitinfo1DIV");

 if (gpIcons.length === 0) return;

 g.setAttribute("src", gpIcons[0].getAttribute("src"));
 g.style.paddingLeft = "4px";
 g.style.paddingTop = "4px";

 p.setAttribute("src", gpIcons[1].getAttribute("src"));
 p.style.paddingLeft = "4px";

 m1.setAttribute("src", "");
 m2.setAttribute("src", "");
 m3.setAttribute("src", "");

 let count = 0;

 if (meritIcons.length !== 0) {
 meritIcons.each(function (key, value) {
 count = key + 1;

 if (count === 1) {
 m1.setAttribute("src", value.getAttribute("src"));
 m1.style.position = "absolute";
 m1.style.paddingLeft = "0px";
 m1.style.paddingTop = "4px";
 } else if (count === 2) {
 m2.setAttribute("src", value.getAttribute("src"));
 m2.style.position = "absolute";
 m2.style.paddingLeft = "10px";
 m2.style.paddingTop = "4px";
 } else if (count === 3) {
 m3.setAttribute("src", value.getAttribute("src"));
 m3.style.position = "absolute";
 m3.style.paddingLeft = "20px";
 m3.style.paddingTop = "4px";
 }
 })
 }

 let unitStats = unitData.find("span");
 let unitStatsIcons = unitData.find("img");

 let sPercent = Math.round((unitStats[1].innerHTML / unitStats[3].innerHTML) \* 100);
 let aPercent = Math.round((unitStats[4].innerHTML / unitStats[5].innerHTML) \* 100);

 s.innerHTML = ":" + sPercent + "%";
 s.style.position = "absolute";
 s.style.paddingLeft = "50px";

 a.innerHTML = ":" + aPercent + "%";
 a.style.position = "absolute";
 a.style.paddingLeft = "50px";
 a.style.paddingTop = "10px";
 sIcon.setAttribute("src", unitStatsIcons[1].getAttribute("src"));
 sIcon.style.position = "absolute";
 sIcon.style.paddingLeft = "40px";
 sIcon.style.paddingTop = "3px";

 aIcon.setAttribute("src", unitStatsIcons[2].getAttribute("src"));
 aIcon.style.position = "absolute";
 aIcon.style.paddingLeft = "40px";
 aIcon.style.paddingTop = "13px";
 }
 });
 }, false)
 });

 let unit = window.frames[2].document.querySelector("#orders1textDIV");
 let ordersDiv = window.frames[2].document.querySelector("#orders1DIV");
 let previousValue = "none";

 p.setAttribute("id", "pthurston-1");
 g.setAttribute("id", "gthurston-1");
 br.setAttribute("id", "gtbr-1");

 let observer = new MutationObserver(function(mutations) {
 mutations.forEach(function(mutation) {
 if (mutation.attributeName !== "style") return;
 let currentValue = mutation.target.style.display;

 if (currentValue !== previousValue) {
 let pExists = !!window.frames[2].document.getElementById("pthurston-1");
 let gExists = !!window.frames[2].document.getElementById("gthurston-1");

 if (previousValue === "none" && currentValue !== "none") {
 if (!pExists && !gExists) {
 unit.appendChild(g);

 unit.appendChild(sIcon);
 unit.appendChild(s);

 unit.appendChild(aIcon);
 unit.appendChild(a);

 unit.appendChild(m1);
 unit.appendChild(m2);
 unit.appendChild(m3);

 unit.appendChild(br);
 unit.appendChild(p);
 }
 } else {
 if (pExists && gExists) {

 if (!!window.frames[2].document.getElementById("meritthurston-1")) {
 unit.removeChild(window.frames[2].document.getElementById("meritthurston-1"));
 }

 if (!!window.frames[2].document.getElementById("meritthurston-2")) {
 unit.removeChild(window.frames[2].document.getElementById("meritthurston-2"));
 }

 if (!!window.frames[2].document.getElementById("meritthurston-3")) {
 unit.removeChild(window.frames[2].document.getElementById("meritthurston-3"));
 }

 unit.removeChild(window.frames[2].document.getElementById("pthurston-1"));
 unit.removeChild(window.frames[2].document.getElementById("gthurston-1"));
 }
 }
 previousValue = mutation.target.style.display;
 }
 });
 });

 observer.observe(ordersDiv, { attributes: true });

 }, 2000);

})();

```