MZ - Players Grouped by Age in Other Teams' Player Pages

Displays players grouped by age in other teams' player pages

当前为 2024-12-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MZ - Players Grouped by Age in Other Teams' Player Pages
// @namespace    douglaskampl
// @version      1.1
// @description  Displays players grouped by age in other teams' player pages
// @author       Douglas
// @match        https://www.managerzone.com/?p=players&tid=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=managerzone.com
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const ageCountMap = new Map();
    document.querySelectorAll('#players_container .playerContainer').forEach(player => {
        let ageElement = player.querySelector('td');
        if (ageElement) {
            let age = parseInt(ageElement.textContent.replace(/\D/g, '').trim());
            if (ageCountMap.has(age)) {
                ageCountMap.set(age, ageCountMap.get(age) + 1);
            } else {
                ageCountMap.set(age, 1);
            }
        }
    });

    const playerFiltersElement = document.querySelector('#player_filters');
    if (playerFiltersElement) {
        const table = document.createElement('table');
        table.id = 'ageTable';

        const thead = document.createElement('thead');
        const tbody = document.createElement('tbody');

        const headerRow = document.createElement('tr');
        const ageHeader = document.createElement('th');
        ageHeader.textContent = 'Age';
        const countHeader = document.createElement('th');
        countHeader.textContent = 'Count';

        headerRow.appendChild(ageHeader);
        headerRow.appendChild(countHeader);
        thead.appendChild(headerRow);
        table.appendChild(thead);

        const tableEntries = Array.from(ageCountMap.entries());
        tableEntries.sort((a, b) => a[0] - b[0]);

        tableEntries.forEach(([age, count]) => {
            const row = document.createElement('tr');
            const ageCell = document.createElement('td');
            ageCell.textContent = age;
            const countCell = document.createElement('td');
            countCell.textContent = count;
            row.appendChild(ageCell);
            row.appendChild(countCell);
            tbody.appendChild(row);
        });

        table.appendChild(tbody);
        playerFiltersElement.appendChild(table);
    }
})();

GM_addStyle(`
    #ageTable {
        border-collapse: separate;
        border-spacing: 0;
        color: white;
        width: 100px;
        font-size: 11px;
        display: inline-block;
        vertical-align: top;
        margin-left: 10px;
    }
    #ageTable th,
    #ageTable td {
        padding: 1px 4px;
        color: white;
    }
    #ageTable thead tr {
        background-color: #000080;
        color: #FFFF00;
    }
    #ageTable tbody tr:nth-child(even) {
        background-color: #000080;
    }
    #ageTable tbody tr:nth-child(odd) {
        background-color: #FF1493;
    }
    #ageTable tbody tr:hover {
        background-color: #00BFFF;
        color: black;
    }
    #ageTable th, #ageTable td {
        font-weight: normal;
        border: 1px solid #1E90FF;
        text-align: center;
    }
    #ageTable th {
        border-top: 2px solid #00BFFF;
        border-bottom: 2px solid #0000FF;
    }
`);