MZ • Destaque Atributos Maximizados

Destaca atributos maximizados (classe .maxed) nas páginas de jogadores, plantel e transferências do ManagerZone. Visual refinado e leve em execução. Compatível com mobile.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         MZ • Destaque Atributos Maximizados
// @namespace    MZTools
// @version      0.4
// @description  Destaca atributos maximizados (classe .maxed) nas páginas de jogadores, plantel e transferências do ManagerZone. Visual refinado e leve em execução. Compatível com mobile.
// @author       Emanuel
// @match        https://www.managerzone.com/*
// @icon         https://www.managerzone.com/images/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(() => {
    'use strict';

    // === CONFIGURAÇÕES ===
    const HIGHLIGHT_COLOR = '#ffcccc'; // 🔧 vermelho suave (visual refinado)
    const STYLE_ID = 'mz-maxed-highlight-style';

    // === INSERE CSS PERSONALIZADO ===
    function injectStyle(doc = document) {
        if (doc.getElementById(STYLE_ID)) return;
        const style = doc.createElement('style');
        style.id = STYLE_ID;
        style.textContent = `
            span.maxed {
                background-color: ${HIGHLIGHT_COLOR} !important;
                color: #000 !important;
                border-radius: 4px;
                padding: 0 3px;
            }
            td.mz-maxed-prev {
                background-color: ${HIGHLIGHT_COLOR} !important;
                border-radius: 3px;
            }
        `;
        doc.head.appendChild(style);
    }

    // === DESTACA ATRIBUTOS MAXIMIZADOS ===
    function highlightMaxedAttributes(root = document) {
        const maxedElements = root.querySelectorAll('span.maxed');
        maxedElements.forEach(el => {
            const td = el.closest('td');
            if (td && td.previousElementSibling) {
                td.previousElementSibling.classList.add('mz-maxed-prev');
            }
        });
    }

    // === MONITORA MUDANÇAS NA PÁGINA ===
    function observePageChanges(root = document) {
        const observer = new MutationObserver(() => highlightMaxedAttributes(root));
        observer.observe(root.body, { childList: true, subtree: true });
    }

    // === EXECUTA EM DOCUMENTOS E IFRAMES ===
    function applyToDocument(doc) {
        try {
            injectStyle(doc);
            highlightMaxedAttributes(doc);
            observePageChanges(doc);
        } catch (e) {
            console.warn('[MZ%] Erro ao aplicar destaque:', e);
        }
    }

    // === EXECUÇÃO INICIAL ===
    function init() {
        const url = window.location.href;
        const validPages = ['p=players', 'p=player', 'p=transfer', 'p=transfers'];
        if (!validPages.some(page => url.includes(page))) return;

        applyToDocument(document);

        // percorre iframes (usado na tela de transferências)
        document.querySelectorAll('iframe').forEach(frame => {
            try {
                if (frame.contentDocument) {
                    applyToDocument(frame.contentDocument);
                }
            } catch { /* ignora iframes cross-domain */ }
        });

        console.log('[MZ%] Destaque Atributos Maximizados v0.4 ativo (visual refinado).');
    }

    // === ESPERA DOM ===
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();