FMP Player Stats Summary (Dynamic + Styled)

Show totals & average rating + auto-update on competition change

Από την 31/05/2025. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         FMP Player Stats Summary (Dynamic + Styled)
// @namespace    https://osama.dev
// @version      1.6
// @description  Show totals & average rating + auto-update on competition change
// @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 recordsSection = document.querySelector('#Records');
        if (!recordsSection) return;

        const table = recordsSection.querySelector('table.recordstable');
        if (!table) return;

        // تأكد إن ما فيش صف سابق من قبل
        if (table.querySelector('tr[data-summary]')) {
            table.querySelector('tr[data-summary]').remove();
        }

        const rows = Array.from(table.querySelectorAll('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');
            if (cells.length >= 9) {
                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.setAttribute('data-summary', 'true');
        summaryRow.style.backgroundColor = '#1d3322';
        summaryRow.style.color = '#FFD700';
        summaryRow.style.fontWeight = 'bold';
        summaryRow.style.fontFamily = 'monospace';
        summaryRow.style.borderTop = '2px solid #888';

        summaryRow.innerHTML = `
            <td colspan="3" style="text-align:left;">📊 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.appendChild(summaryRow);
    }

    function observeTableChanges() {
        const target = document.querySelector('#Records');
        if (!target) return;

        const observer = new MutationObserver(() => {
            setTimeout(addStatsSummary, 300); // ندي فرصة للبيانات تنزل
        });

        observer.observe(target, {
            childList: true,
            subtree: true
        });
    }

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