FMP Player Stats Summary

Show totals and average rating for player performance table

Per 31-05-2025. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         FMP Player Stats Summary
// @namespace    https://osama.dev
// @version      1.1
// @description  Show totals and average rating for player performance table
// @match        https://footballmanagerproject.com/Team/Player?id=*
// @grant        none
// ==/UserScript==

(function () {
    function parseNum(txt) {
        const n = parseFloat(txt);
        return isNaN(n) ? 0 : n;
    }

    function addStatsSummary() {
        const table = document.querySelector('#recordstable');
        if (!table) return;

        const rows = Array.from(table.querySelectorAll('tbody tr')).filter(r => r.children.length >= 9);
        if (!rows.length) return;

        let totals = { matches: 0, goals: 0, assists: 0, yellow: 0, red: 0, rating: 0 };
        let ratingCount = 0;

        rows.forEach(row => {
            const cells = row.querySelectorAll('td');
            totals.matches += parseNum(cells[3].innerText);
            totals.goals += parseNum(cells[4].innerText);
            totals.assists += parseNum(cells[5].innerText);
            totals.yellow += parseNum(cells[6].innerText);
            totals.red += parseNum(cells[7].innerText);
            const rate = parseNum(cells[8].innerText);
            if (rate > 0) {
                totals.rating += rate;
                ratingCount++;
            }
        });

        const avgRating = ratingCount ? (totals.rating / ratingCount).toFixed(2) : '0.00';

        const summaryRow = document.createElement('tr');
        summaryRow.style.backgroundColor = '#334400';
        summaryRow.style.color = 'yellow';
        summaryRow.style.fontWeight = 'bold';

        summaryRow.innerHTML = `
            <td colspan="3">📊 Summary</td>
            <td>${totals.matches}</td>
            <td>${totals.goals}</td>
            <td>${totals.assists}</td>
            <td>${totals.yellow}</td>
            <td>${totals.red}</td>
            <td>${avgRating}</td>
            <td></td>
        `;

        table.querySelector('tbody').appendChild(summaryRow);
    }

    window.addEventListener('load', () => {
        setTimeout(addStatsSummary, 1200);
    });
})();