MediaWiki:Common.js: відмінності між версіями

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 1075: Рядок 1075:
     $btn.on('click', doSearch);
     $btn.on('click', doSearch);
     $input.on('keydown', function (e) { if (e.keyCode === 13) { e.preventDefault(); doSearch(); } });
     $input.on('keydown', function (e) { if (e.keyCode === 13) { e.preventDefault(); doSearch(); } });
});
// ============================================================
// ДОДАТИ в кінець Common.js (після всього іншого коду)
// ============================================================
// ── 1. PLAYER TABS — перетворюємо "(42)" на стилізований badge ──
$(function () {
    $('.player-tab').each(function () {
        var $tab = $(this);
        var text = $tab.text();
        // Шукаємо "(число)" в тексті табу
        var m = text.match(/\((\d+)\)/);
        if (!m) return;
        // Замінюємо "(42)" на <span class="mcc-tab-cnt">42</span>
        var cleanText = text.replace(/\s*\(\d+\)/, '').trim();
        $tab.text(cleanText);
        $tab.append('<span class="mcc-tab-cnt">' + m[1] + '</span>');
    });
});
// ── 2. СЕЗОНИ — підсвічуємо "Чемпіон" у таблиці ──
$(function () {
    function applySeasonColors($context) {
        var $root = $context || $(document);
        $root.find('.wikitable tbody td').each(function () {
            var $cell = $(this);
            var text  = $cell.text().trim();
            if (text === 'Чемпіон' || text === '♔ Чемпіон') {
                $cell.css({ color: '#7ab8ff', fontWeight: '700' });
            }
        });
    }
    applySeasonColors();
    // Після lazy load теж
    $(document).on('mcc:content-loaded', function () {
        applySeasonColors();
    });
});
// ── 3. ROLE PILLS — окремий надійний виклик ──
// (доповнює applyRolePills з основного коду)
$(function () {
    var roleStyles = {
        'Мир': { bg:'rgba(76,175,125,0.12)', color:'#7dd4a6', border:'rgba(76,175,125,0.22)' },
        'Шер': { bg:'rgba(91,143,255,0.12)', color:'#7da8ff', border:'rgba(91,143,255,0.22)' },
        'Маф': { bg:'rgba(200,76,76,0.12)',  color:'#e08888', border:'rgba(200,76,76,0.22)'  },
        'Дон': { bg:'rgba(255,215,0,0.10)',  color:'#ffd700', border:'rgba(255,215,0,0.22)'  }
    };
    function pillify($root) {
        ($root || $(document)).find('.wikitable tbody td').each(function () {
            var $cell = $(this);
            // Знаходимо span з inline color або просто текст ролі
            var $span = $cell.find('span').filter(function () {
                return $(this).attr('style') && $(this).attr('style').indexOf('color') !== -1;
            });
            var $target = $span.length ? $span : null;
            var roleText = $target ? $target.text().trim() : $cell.text().trim();
            var style    = roleStyles[roleText];
            if (!style) return;
            if (!$target) {
                // Якщо просто текст — обгортаємо
                var html = $cell.html();
                $cell.html('<span class="mcc-role-pill">' + html + '</span>');
                $target = $cell.find('.mcc-role-pill');
            }
            if (!$target.hasClass('mcc-pill-done')) {
                $target.addClass('mcc-pill-done').css({
                    display:      'inline-block',
                    padding:      '2px 10px',
                    borderRadius:  '4px',
                    fontSize:      '12.5px',
                    fontWeight:    '600',
                    background:    style.bg,
                    color:        style.color,
                    border:        '1px solid ' + style.border,
                    fontFamily:    "'Manrope', sans-serif"
                });
            }
        });
    }
    pillify();
    $(document).on('mcc:content-loaded', function () { pillify(); });
});
// ── 4. PROFILE ICONS — перевіряємо та фіксуємо layout ──
$(function () {
    function fixProfileIcons() {
        var $icons = $('.profile-links-icons');
        if (!$icons.length) return;
        // Примусово перевизначаємо через JS якщо CSS не спрацював
        $icons.css({
            'display': 'grid',
            'grid-template-columns': 'repeat(4, 1fr)',
            'gap': '0'
        });
        $icons.find('.profile-icon').css({
            'display': 'flex',
            'align-items': 'center',
            'justify-content': 'center',
            'padding': '13px 4px',
            'float': 'none',
            'width': 'auto'
        });
    }
    // Запускаємо одразу і через затримку (після рендеру)
    fixProfileIcons();
    setTimeout(fixProfileIcons, 300);
});
});