FMP Player Stats Averager

Calculate total and average for player stats on profile page

2025-05-31 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         FMP Player Stats Averager
// @namespace    https://osama.dev
// @version      1.0
// @description  Calculate total and average for player stats on profile page
// @match        https://footballmanagerproject.com/Team/Player?id=*
// @grant        none
// ==/UserScript==

(function () {
    function parseNumber(text) {
        const val = parseFloat(text);
        return isNaN(val) ? 0 : val;
    }

    function format(value, decimals = 2) {
        return Number(value).toFixed(decimals);
    }

    function processStats() {
        const table = document.querySelector('table');
        if (!table) return;

        const rows = Array.from(table.querySelectorAll('tbody tr'));
        const 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 >= 10) {
                totals.matches += parseNumber(cells[3].innerText);
                totals.goals += parseNumber(cells[4].innerText);
                totals.assists += parseNumber(cells[5].innerText);
                totals.yellow += parseNumber(cells[6].innerText);
                totals.red += parseNumber(cells[7].innerText);
                const rating = parseNumber(cells[8].innerText);
                if (rating > 0) {
                    totals.rating += rating;
                    ratingCount++;
                }
            }
        });

        // أضف صف جديد أسفل الجدول
        const avgRating = ratingCount ? totals.rating / ratingCount : 0;

        const summaryRow = document.createElement('tr');
        summaryRow.style.fontWeight = 'bold';
        summaryRow.style.color = 'yellow';
        summaryRow.innerHTML = `
            <td colspan="3">📊 Totals:</td>
            <td>${totals.matches}</td>
            <td>${totals.goals}</td>
            <td>${totals.assists}</td>
            <td>${totals.yellow}</td>
            <td>${totals.red}</td>
            <td>${format(avgRating)}</td>
            <td></td>
        `;

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

    window.addEventListener('load', function () {
        setTimeout(processStats, 1000);
    });
})();