Elma / Expe Mili

// ==UserScript==
// @name         Expe Mili
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Expe Mili
// @license MIT
// @author       Elmamich
// @match        https://s161-fr.ogame.gameforge.com/game/index.php?page=ingame&component=fleetdispatch
// @grant        none
// ==/UserScript==

function expe(e) {
  if (e.key.toLowerCase() === 'p') {
    var nb_cle = fleetDispatcher.getNumberOfShipsOnPlanet(204);
    var nb_gt = fleetDispatcher.getNumberOfShipsOnPlanet(203);

    if (nb_cle > 2 * nb_gt) {
      nb_cle = 2 * nb_gt; //ratio fixe 1cle/0.5gt
    }
    else {
      nb_gt = nb_cle / 2;
    }

    var slots_dispo = fleetDispatcher.explorationCount - fleetDispatcher.expeditionCount; //slots libres

    if (slots_dispo > 0) { //evite les divisions par 0

      fleetDispatcher.selectShip(204, Math.ceil(nb_cle / slots_dispo)); //cle
      fleetDispatcher.selectShip(203, Math.ceil(nb_gt / slots_dispo)); //gt
      fleetDispatcher.selectShip(218, 1); //faucheur
      fleetDispatcher.selectShip(219, 1); //éclaireur
      fleetDispatcher.selectShip(210, 1); //sonde

      //affichage

      document.querySelector('input[name=fighterLight]').value = Math.ceil(nb_cle / slots_dispo);
      document.querySelector('input[name=transporterLarge]').value = Math.ceil(nb_gt / slots_dispo);
      document.querySelector('input[name=reaper]').value = 1;
      document.querySelector('input[name=explorer]').value = 1;
      document.querySelector('input[name=espionageProbe]').value = 1;

      document.getElementById('continueToFleet2').className = 'continue on';
      document.getElementById('continueToFleet2').focus();

      fleetDispatcher.targetPlanet.position = 16;
      fleetDispatcher.targetPlanet.type = 1

    }

  }
}

document.addEventListener('keypress', expe);