villoss / botting is bad

// ==UserScript==
// @name         botting is bad
// @namespace    idk man probably this one.
// @version      1.8
// @author       villoss
// @match        https://*.ogame.gameforge.com/game/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addStyle
// @updateURL    https://openuserjs.org/meta/villoss/botting_is_bad.meta.js
// @license      MIT
// ==/UserScript==

var isBotToggled = localStorage.getItem('togglebot'); // will need this to turn on and off the script
if(isBotToggled === null) {
    localStorage.setItem('togglebot',false);
    isBotToggled = localStorage.getItem('togglebot');
}
isBotToggled = (isBotToggled == 'true'); // fuck js

if(window.location.href.indexOf('index.php') != -1) {
    // the two following element create a button to turn on or off the script
    var lefttogglebot = document.createElement('li');
    lefttogglebot.innerHTML = '<span class="menu_icon"><button id="lefttogglebot" class="leftrdmbtn rdmbtn"></button></span><a href="" class="menubutton" target="_self"><span class="textlabel">botting is bad</span></a>';
    document.getElementById('menuTableTools').appendChild(lefttogglebot);
    document.getElementById('lefttogglebot').innerHTML = isBotToggled.toString().toUpperCase().slice(0,1);
    document.getElementById('lefttogglebot').addEventListener("click", invertValue, false);

    var togglebot = document.createElement('button');
    togglebot.setAttribute('id', 'togglebot');
    togglebot.setAttribute('class','rdmbtn');
    togglebot.innerHTML = isBotToggled.toString().toUpperCase().slice(0,1);
}

if(window.location.href.indexOf('fleetdispatch') != -1) {
    const fleetToSend = {
        202:0,
        203:0,// large cargo
        204:0, // light fighter
        205:0,
        206:0,
        207:0,
        208:0,
        209:0,
        210:0, // spy probe
        212:0,
        213:0, // destroyer
        214:0,
        215:0,
        216:0,
        217:0,
        218:0, // reaper
        219:0 // pathfinder
    };

    if (fleetDispatcher.shipsOnPlanet.length > 0) {

        document.getElementsByClassName('secondcol fleft')[0].appendChild(togglebot);
        document.getElementById("togglebot").addEventListener("click", invertValue, false);

        setInterval(() => {
            if ( isBotToggled == true ) { // will refresh every 10 sec to see (1/2)
                let expe = { max:fleetDispatcher.maxExpeditionCount, current:fleetDispatcher.expeditionCount };

                if ( expe.current < expe.max ) { // if an expedition slot is available. (2/2)

                    if ( fleetDispatcher.shipsOnPlanet[0] !== 'undefined' ) {

                        if ( fleetDispatcher.shipsOnPlanet[0].id == 203 || fleetDispatcher.shipsOnPlanet[1].id == 203 ) {

                            const wantedSSrdm = 40; // This part setup the mission to send
                            fleetDispatcher.targetPlanet.system = parseInt(fleetDispatcher.currentPlanet.system) + Math.floor(Math.random() * wantedSSrdm + 1) - (wantedSSrdm/2);
                            fleetDispatcher.targetPlanet.position = 16;
                            fleetDispatcher.targetPlanet.type = 1;
                            fleetDispatcher.mission = 15; // expe mission ID
                            fleetDispatcher.expeditionTime = 1; // in hour

                            for (const [key, value] of Object.entries(fleetToSend)) {
                                fleetDispatcher.selectShip(parseInt(key),parseInt(value));
                            }
                            fleetDispatcher.refresh();

                            document.getElementById('continueToFleet2').click();
                            document.getElementById('continueToFleet3').click();
                            setTimeout(() => {document.getElementById('sendFleet').click();},500); // wait 500ms due to game limitation.
                        }
                    }
                } else { setTimeout(() => {location.reload();}, 10000); }
            }
        }, 10000);
    }
}

function invertValue() { // invert value of the script state.
    isBotToggled = !isBotToggled;
    localStorage.setItem('togglebot',isBotToggled);
    togglebot.innerHTML = isBotToggled.toString().toUpperCase().slice(0,1);
    document.getElementById('lefttogglebot').innerHTML = isBotToggled.toString().toUpperCase().slice(0,1);
}

GM_addStyle(`
.rdmbtn {
box-shadow: inset 0 1px rgba(255,255,255,.2), 0 0 0 1px rgba(0,0,0,.3);
background-color: #375879;
border-radius:3px;
color:white;
text-align:center;
font-weight: bold;
position: relative;
display: inline-block;
cursor: pointer;
width: 30px;
height: 30px;
line-height: 30px;
box-sizing: border-box;
}

.leftrdmbtn {
background:none;
box-shadow:none;
}
`);

// smoking pcp with Metal