Sirius4e / OgameShortcuts

// ==UserScript==
// @name        OgameShortcuts
// @description Adds shortcut buttons to Ogame.
// @match       https://*.ogame.gameforge.com/game/*
// @grant       GM_addStyle
// @license     MIT
// @version     0.2.0
// ==/UserScript==

var searchableStr = document.URL + '&';
var value1 = searchableStr.match(/[?&]component=([^&#]+)[&#]/i)[1];
if (value1 === "fleetdispatch") {
  var zNode = document.createElement('div');
  zNode.innerHTML = '<div style="flex:1"></div>' +
    '<div class="fb_buttons">' +
    '<button id="returnButton" class="button" type="button">' +
    '<span class="enter-icon">⏎</span>' + // Unicode-Enter-Pfeil-Symbol
    '</button>' +
'<button id="collectButton" class="button" type="button">' +
    '<span class="enter-icon">C</span>' + 
    '</button>' +
'<button id="expoButton" class="button" type="button">' +
    '<span class="enter-icon">E</span>' + 
    '</button>' +
    '</div>';
  zNode.setAttribute('id', 'fb_container');
  zNode.setAttribute('style', 'top: 0px; height: calc(100vh - 46px); left: 0px; width: 100vw;');
  document.body.appendChild(zNode);
  document.getElementById("returnButton").addEventListener(
    "click", ButtonClickAction, false
  );
document.getElementById("expoButton").addEventListener(
    "click", ExpoButtonClickAction, false
  );
document.getElementById("collectButton").addEventListener(
    "click", CollectButtonClickAction, false
  );
}
function ButtonClickAction(zEvent) {
  document.querySelector("#fleetdispatchcomponent").dispatchEvent(new KeyboardEvent("keypress", {
          keyCode: 13
        }));
}
function CollectButtonClickAction(zEvent) {
  document.querySelector(".ogl-collect").click();

}
function ExpoButtonClickAction(zEvent) {
  document.querySelector(".ogl-expedition").click();
}

GM_addStyle(`
.fb_buttons {
    display: flex;
    grid-gap: 7px;
    flex-wrap: wrap;
    justify-content: center;
}

#myContainer {
    position: absolute;
    bottom: 0;
    right: 0;
    font-size: 20px;
    background: orange;
    border: 3px outset black;
    margin: 5px;
    opacity: 0.9;
    z-index: 1100;
    padding: 5px 20px;
}

.button {
    border-radius: 25px;
    align-items: center;
    box-shadow: 0 0 5px rgba(255, 255, 255, .6);
    display: inline-flex;
    font-size: 11px;
    grid-gap: 5px;
    justify-content: center;
    line-height: 40px;
    width: 120px;
    height: 120px;
    pointer-events: all;
    text-transform: capitalize;
    background-color: #000;
    color: #c0c0c0;
}

#fb_container {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    pointer-events: none;
    position: fixed;
    text-transform: uppercase;
    z-index: 10;
    top: 0;
    height: calc(100vh - 25px);
    left: 0;
    width: 100vw;
}

.enter-icon {
    font-size: 90px; // Schriftgröße anpassen, damit das Symbol den Platz ausfüllt
    line-height: 1;
}
`);