6369
редагувань
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 886: | Рядок 886: | ||
// ============================================================ | // ============================================================ | ||
// SEASON RATING TABLE — medals, | // SEASON RATING TABLE — medals + column colors | ||
// Detects tables with headers: № | name | Σ | І | % | |||
// Adds .mcc-rating-table class, then processes columns | |||
// ============================================================ | // ============================================================ | ||
$(function () { | $(function () { | ||
function processRatingTable($t) { | |||
// Collect header texts | |||
var headers = []; | var headers = []; | ||
$t.find(' | $t.find('tr').first().find('th').each(function () { | ||
headers.push($(this).text().trim()); | headers.push($(this).text().trim()); | ||
}); | }); | ||
// Must have | // Must start with № and have Σ at index 2 | ||
if (headers[0] !== '№') return; | |||
if (headers.length < 4) return; | |||
var | // At least one of Σ, І, % must be present | ||
var hasPct | var hasSigma = headers[2] === 'Σ'; | ||
if (!hasSigma) return; | |||
var iGames = 3; // І | |||
var iPct = 4; // % | |||
var hasI = headers[iGames] === 'І'; | |||
var hasPct = headers[iPct] === '%'; | |||
// Mark table | |||
$t.addClass('mcc-rating-table'); | |||
var $rows = $t.find('tbody tr').filter(function () { | var $rows = $t.find('tbody tr').filter(function () { | ||
return $(this).find('td').length >= 4; | return $(this).find('td').length >= 4; | ||
}); | }); | ||
if (!$rows.length) return; | if (!$rows.length) return; | ||
// | // 1. Medal badges — top 3 | ||
$rows.each(function () { | $rows.each(function () { | ||
var $tds = $(this).find('td'); | var $tds = $(this).find('td'); | ||
var | var n = parseInt($tds.eq(0).text().trim()); | ||
if (n >= 1 && n <= 3) { | |||
$tds.eq(0).html('<span class="mcc-rank-' + n + '">' + n + '</span>'); | |||
if (n | |||
$tds.eq( | |||
} | } | ||
}); | }); | ||
// | // 2. Σ white — done via CSS .mcc-rating-table td:nth-child(3) | ||
// | // 3. Games (І) — max green, min red | ||
if (hasI) { | if (hasI) { | ||
var | var gVals = []; | ||
$rows.each(function () { | $rows.each(function () { | ||
var v = parseInt($(this).find('td').eq(iGames).text().trim()); | var v = parseInt($(this).find('td').eq(iGames).text().trim()); | ||
if (!isNaN(v)) | if (!isNaN(v) && v > 0) gVals.push(v); | ||
}); | }); | ||
if ( | if (gVals.length > 1) { | ||
var gMax = Math.max.apply(null, | var gMax = Math.max.apply(null, gVals); | ||
var gMin = Math.min.apply(null, | var gMin = Math.min.apply(null, gVals); | ||
$rows.each(function () { | $rows.each(function () { | ||
var $td = $(this).find('td').eq(iGames); | var $td = $(this).find('td').eq(iGames); | ||
| Рядок 958: | Рядок 949: | ||
} | } | ||
// | // 4. WR (%) — max green, min red | ||
if (hasPct) { | if (hasPct) { | ||
var | var pVals = []; | ||
$rows.each(function () { | $rows.each(function () { | ||
var | var v = parseFloat($(this).find('td').eq(iPct).text().trim().replace('%','')); | ||
if (!isNaN(v)) pVals.push(v); | |||
if (!isNaN(v)) | |||
}); | }); | ||
if ( | if (pVals.length > 1) { | ||
var pMax = Math.max.apply(null, | var pMax = Math.max.apply(null, pVals); | ||
var pMin = Math.min.apply(null, | var pMin = Math.min.apply(null, pVals); | ||
$rows.each(function () { | $rows.each(function () { | ||
var $td = $(this).find('td').eq(iPct); | var $td = $(this).find('td').eq(iPct); | ||
| Рядок 978: | Рядок 968: | ||
} | } | ||
} | } | ||
} | |||
// Run on all wikitables | |||
$('.content .mw-parser-output .wikitable').each(function () { | |||
processRatingTable($(this)); | |||
}); | }); | ||
}); | }); | ||