Raw Source
hedex / OGame Fleet Points Calculator

// ==UserScript==
// @name         OGame Fleet Points Calculator
// @namespace    http://tampermonkey.net/
// @version      0.0.2+
// @description  Calculates fleet points in the OGame fleets screen and displays them on the page
// @author       hedex
// @license      MIT
// @match        *://*.ogame.gameforge.com/game/index.php?page=ingame&component=fleetdispatch*
// @updateURL https://openuserjs.org/meta/hedex/Fleet_points_calculator.meta.js
// @downloadURL https://openuserjs.org/install/hedex/Fleet_points_calculator.user.js
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    const shipValues = {
      'Small Cargo': 4000,
      'Large Cargo': 12000,
      'Light Fighter': 4000,
      'Heavy Fighter': 10000,
      'Cruiser': 29000,
      'Battleship': 60000,
      'Colony Ship': 40000,
      'Recycler': 18000,
      'Espionage Probe': 1000,
      'Bomber': 90000,
      'Destroyer': 125000,
      'Deathstar': 10000000,
      'Battlecruiser': 85000,
      'Reaper': 160000,
      'Pathfinder': 31000
    };

    const ships = [
        { name: 'Small Cargo', xpath: '//*[@id="civil"]/li[1]/span/span[1]' },
        { name: 'Large Cargo', xpath: '//*[@id="civil"]/li[2]/span/span[1]' },
        { name: 'Colony Ship', xpath: '//*[@id="civil"]/li[3]/span/span[1]' },
        { name: 'Recycler', xpath: '//*[@id="civil"]/li[4]/span/span[1]' },
        { name: 'Espionage Probe', xpath: '//*[@id="civil"]/li[5]/span/span[1]' },
        { name: 'Light Fighter', xpath: '//*[@id="military"]/li[1]/span/span[1]' },
        { name: 'Heavy Fighter', xpath: '//*[@id="military"]/li[2]/span/span[1]' },
        { name: 'Cruiser', xpath: '//*[@id="military"]/li[3]/span/span[1]' },
        { name: 'Battleship', xpath: '//*[@id="military"]/li[4]/span/span[1]' },
        { name: 'Battlecruiser', xpath: '//*[@id="military"]/li[5]/span/span[1]' },
        { name: 'Bomber', xpath: '//*[@id="military"]/li[6]/span/span[1]' },
        { name: 'Destroyer', xpath: '//*[@id="military"]/li[7]/span/span[1]' },
        { name: 'Deathstar', xpath: '//*[@id="military"]/li[8]/span/span[1]' },
        { name: 'Reaper', xpath: '//*[@id="military"]/li[9]/span/span[1]' },
        { name: 'Pathfinder', xpath: '//*[@id="military"]/li[10]/span/span[1]' }
    ];

    function getShipCount(xpath) {
        const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
        return result.singleNodeValue ? parseInt(result.singleNodeValue.textContent.replace(/\D/g, ''), 10) : 0;
    }

    function calculateFleetPoints() {
        let totalPoints = 0;

        ships.forEach(ship => {
            const count = getShipCount(ship.xpath);
            const points = count * (shipValues[ship.name] || 0);
            totalPoints += points;
        });

        displayFleetPoints(totalPoints);
    }

    function displayFleetPoints(totalPoints) {
        let fleetPointsPanel = document.getElementById('fleetPointsPanel');
        const menuElement = document.evaluate('//*[@id="toolbarcomponent"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

        if (!fleetPointsPanel) {
            fleetPointsPanel = document.createElement('div');
            fleetPointsPanel.id = 'fleetPointsPanel';
            fleetPointsPanel.style.position = 'absolute';
            fleetPointsPanel.style.padding = '10px';
            fleetPointsPanel.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
            fleetPointsPanel.style.color = 'white';
            fleetPointsPanel.style.fontSize = '14px';
            fleetPointsPanel.style.borderRadius = '5px';
            fleetPointsPanel.style.zIndex = '1000';
            document.body.appendChild(fleetPointsPanel);
        }

        if (menuElement) {
            const position = menuElement.getBoundingClientRect();
            fleetPointsPanel.style.top = `${position.bottom + window.scrollY + 10}px`; 
            fleetPointsPanel.style.left = `${position.left + window.scrollX}px`;
        }

        fleetPointsPanel.innerHTML = `Total fleet points:<br>${totalPoints.toLocaleString('it-IT')}`;
    }

    window.addEventListener('load', calculateFleetPoints);
})();