Yog / Pardus Quick Utilities

// ==UserScript==
// @name          Pardus Quick Utilities
// @namespace     pardus.at
// @author        Yog
// @version       1.2
// @license       GPL-3.0-only
// @description   Adds links, warnings, input values
// @include       *.pardus.at/main.php*
// @match         *.pardus.at/main.php*
// @include       *.pardus.at/drop_cargo.php*
// @match         *.pardus.at/drop_cargo.php*
// @include       *.pardus.at/ship2opponent_combat.php*
// @match         *.pardus.at/ship2opponent_combat.php*
// ==/UserScript==

// --User Options---------------------------------------------------
// Use this section to turn on/off features created by the script.
// Just change from 'true' to 'false' to turn something off..

// https://userstyles.org/styles/167883/pardus-style-remake-2-0
var NoPardusStyleRemakeInstalled = true;

var enableBulletinBoard = true;
var enableCrewQuarters = true;
var enableRechargeShield = true;

// --end User Options-----------------------------------------------

function fuelWarning() {
    var fuelInCargo = parseInt(document.getElementById('tdCargoRes16').getElementsByTagName("font")[0].textContent);
    var fuelElem = document.getElementById('fuel');
    if(parseInt(fuelElem.textContent) < (4 - fuelInCargo)) {
        fuelElem.classList.add('mark-warning');
        document.getElementById('status_content').classList.add('is-relative');
    }
    if(parseInt(fuelElem.textContent) < (2 - fuelInCargo)) {
        fuelElem.classList.add('mark-critical');
    }
}

function addLinks() {
  // add links to Status, Commands, Ships, and Other Ships panel
    var position;
    if (document.getElementById('nav').style.display === 'none') {
        position = document.querySelector('#navtransition').querySelector('#stdCommand').getElementsByTagName("img")[0].getAttribute('src');
    } else {
        position = document.getElementById('stdCommand').getElementsByTagName("img")[0].getAttribute('src');
    }
    var child = document.createElement("span");
//    child.setAttribute("id", position);
//    if (document.getElementById('nav').style.display === 'none') child.innerHTML = 'tr';
//    else child.innerHTML = 'nav';
    document.getElementById('commands_content').getElementsByTagName("div")[0].append(child);

    if(enableBulletinBoard) {
      if(position.search(/starbase/i) != -1 || position.search(/planet/i) != -1) {
        child.innerHTML += "<br><a href='bulletin_board.php'>Bulletin Board</a>";
      }
    }
    if(enableCrewQuarters) {
      if(position.search(/planet/i) != -1) {
        child.innerHTML += "<br><a href='crew_quarters.php'>Crew Quarters</a>";
      }
    }
    if(enableRechargeShield) {
      if(position.search(/energy_well/i) != -1) {
         child.innerHTML += "<br><a href='energy_well.php'>Recharge Shield</a>";
      }
    }
    /* hide with partial refresh, but not naving */
    document.getElementById('commands_content').querySelector('div > span:nth-last-child(2)').style.display = "none";
}

// radiation counter
function radCounter() {
    var HullInt = parseInt(document.getElementById('spanShipHull').textContent);
    HullInt = Math.floor(HullInt / 8);
    var hullHours = Math.floor(HullInt * 0.1);
    var hullMinutes = (HullInt * 6) % 60;
    var color = "";
    if (hullHours < 2) color = "yellow";
    if (document.getElementById('tdShipHull').getElementsByTagName('img').length > 0) {
        document.getElementById('tdShipHull').innerHTML +=
        "<br><font size='1' color='" + color + "' >" + hullHours + "hours " + hullMinutes + "minutes left</font>";
    }
}

// handle partial refresh scenario
function handleRefresh() {
	if (unsafeWindow.checkToDo !== undefined) {
		var local_checkToDo = unsafeWindow.checkToDo;
		unsafeWindow.checkToDo = function() {
			local_checkToDo();
			setTimeout(fuelWarning,1);
			setTimeout(addLinks,1);
			setTimeout(radCounter,1);
		};
	}
	fuelWarning();
	addLinks();
    radCounter();
}
if (document.location.href.match('main.php')) handleRefresh();

// drop waste
function dropWaste() {
    var wasteAmount = document.getElementById('res_21').parentNode.previousSibling.textContent;
    document.getElementById('res_21').value = wasteAmount;
}
if (document.location.href.match('drop_cargo.php')) dropWaste();


// npc combat screen fill up tank
function addFillTank() {
  if (document.location.href.match('ship2opponent_combat.php')) {

  }
}

// styling
if(NoPardusStyleRemakeInstalled && document.location.href.match('main.php')) {
  (function() {var css = [
	"#status_content.is-relative {",
	"    position: relative;",
	"    z-index:1;",
	"    text-shadow: 0 0 2px black;",
	"}",
	".mark-warning {",
	"    position: relative;",
	"}",
	".mark-critical {",
	"    color: red;",
	"    text-shadow: 1px 0 2px black, -1px 0 2px black;",
	"}",
	".mark-warning:after {",
	"    content: \'\';",
	"    position: absolute;",
	"    top: 50%;",
	"    left: 50%;",
	"    margin: -20px 0 0 -19px;",
	"    padding: 20px;",
	"	border-radius: 50%;",
	"	background: rgba(255, 0, 0, .4);",
	"	animation: emerging .5s ease-in-out;",
	"    z-index: -1;",
	"}",
	".mark-critical:after {",
	"    margin: -30px 0 0 -30px;",
	"    padding: 30px;",
	"	background: rgba(255, 0, 0, .6);",
	"}",
	"@keyframes emerging {",
	"  0% {",
	"    opacity: 0;",
	"    transform:scale(0);",
	"  }",
	"  70% {",
	"    opacity: 1;",
	"    transform:scale(1.6);",
	"  }",
	"  100% {",
	"    opacity: 1;",
	"    transform:scale(1);",
	"  }",
	"}"
  ].join("\n")
  var node = document.createElement("style");
  node.type = "text/css";
  node.appendChild(document.createTextNode(css));
  var heads = document.getElementsByTagName("head");
  if (heads.length > 0) {
  	heads[0].appendChild(node);
  } else {
  	// no head yet, stick it whereever
  	document.documentElement.appendChild(node);
  }
  })();
}