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

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 882: Рядок 882:
     // Inject filters
     // Inject filters
     buildGamesFilters($content, $table);
     buildGamesFilters($content, $table);
});
// ============================================================
// SEASON RATING TABLE — medals, color extremes
// ============================================================
$(function () {
    // Find rating tables on season pages
    // Rating table has columns: № | Пан/Пані | Σ | І | %
    // We detect by: first th text = "№" or "Пан/Пані" nearby
    $('.content .mw-parser-output .wikitable').each(function () {
        var $t = $(this);
        var headers = [];
        $t.find('thead tr:first th, tr:first th').each(function () {
            headers.push($(this).text().trim());
        });
        // Must have №, Σ, І, % columns — rating table signature
        var hasNum  = headers[0] === '№';
        var hasSigma = headers.indexOf('Σ') !== -1 || headers[2] === 'Σ';
        var hasI    = headers.indexOf('І') !== -1 || headers[3] === 'І';
        var hasPct  = headers.indexOf('%') !== -1 || headers[4] === '%';
        if (!hasNum || !hasSigma) return;
        var $rows = $t.find('tbody tr').filter(function () {
            return $(this).find('td').length >= 4;
        });
        if (!$rows.length) return;
        // Col indices
        var iNum  = 0; // №
        var iName  = 1; // Пан/Пані
        var iSigma = 2; // Σ
        var iGames = 3; // І
        var iPct  = 4; // %
        // ── 1. Medal badges for top 3 ──
        $rows.each(function () {
            var $tds = $(this).find('td');
            var numCell = $tds.eq(iNum).text().trim();
            var n = parseInt(numCell);
            if (isNaN(n)) return;
            if (n === 1 || n === 2 || n === 3) {
                var cls = 'mcc-rank-' + n;
                $tds.eq(iNum).html('<span class="' + cls + '">' + n + '</span>');
            }
        });
        // ── 2. Σ column — white (CSS handles, but clear any conflicting color) ──
        $rows.each(function () {
            var $td = $(this).find('td').eq(iSigma);
            $td.css({ color: '#ffffff', fontWeight: '700' });
        });
        // ── 3. Games (І) — highlight max/min ──
        if (hasI) {
            var gamesVals = [];
            $rows.each(function () {
                var v = parseInt($(this).find('td').eq(iGames).text().trim());
                if (!isNaN(v)) gamesVals.push(v);
            });
            if (gamesVals.length) {
                var gMax = Math.max.apply(null, gamesVals);
                var gMin = Math.min.apply(null, gamesVals);
                $rows.each(function () {
                    var $td = $(this).find('td').eq(iGames);
                    var v = parseInt($td.text().trim());
                    if (isNaN(v)) return;
                    if (v === gMax) $td.addClass('mcc-games-hi');
                    else if (v === gMin) $td.addClass('mcc-games-lo');
                });
            }
        }
        // ── 4. WR (%) — highlight max/min ──
        if (hasPct) {
            var pctVals = [];
            $rows.each(function () {
                var raw = $(this).find('td').eq(iPct).text().trim().replace('%','');
                var v = parseFloat(raw);
                if (!isNaN(v)) pctVals.push(v);
            });
            if (pctVals.length) {
                var pMax = Math.max.apply(null, pctVals);
                var pMin = Math.min.apply(null, pctVals);
                $rows.each(function () {
                    var $td = $(this).find('td').eq(iPct);
                    var v = parseFloat($td.text().trim().replace('%',''));
                    if (isNaN(v)) return;
                    if (v === pMax) $td.addClass('mcc-wr-hi');
                    else if (v === pMin) $td.addClass('mcc-wr-lo');
                });
            }
        }
    });
});
});


// ============================================================
// ============================================================
// 17. BANNER SEARCH
// 17. BANNER SEARCH