MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 315: | Строка 315: | ||
factor = 1.1 + (35 - brightness) / 50; // Темный цвет с доминированием синего | factor = 1.1 + (35 - brightness) / 50; // Темный цвет с доминированием синего | ||
} | } | ||
} else if (brightness <= 55) { | |||
factor = 1.085; | |||
} else if (brightness < 140) { | } else if (brightness < 140) { | ||
if (r > g && r > b) { | if (r > g && r > b) { | ||
factor = 1. | factor = 1.035 + (140 - brightness) / 300; // Корректируем, чтобы красный не пересвечивался | ||
} else { | } else { | ||
factor = 1. | factor = 1.045; | ||
} | } | ||
} else if (brightness < 180) { | |||
factor = 1.02; | |||
} else { | } else { | ||
factor = 1.0; | factor = 1.0; | ||
| Строка 337: | Строка 339: | ||
// Функция для подсветки ячеек в таблице при наведении | // Функция для подсветки ячеек в таблице при наведении | ||
function applyHighlighting() { | function applyHighlighting() { | ||
if (/Mobi|Android/i.test(navigator.userAgent)) { | if (/Mobi|Android/i.test(navigator.userAgent)) { | ||
return; | return; | ||
} | } | ||
var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | ||
Array.prototype.forEach.call(tables, function(table) { | Array.prototype.forEach.call(tables, function(table) { | ||
var tbody = table.querySelector('tbody'); | var tbody = table.querySelector('tbody'); | ||
| Строка 351: | Строка 350: | ||
var noHeader = table.classList.contains('no-header-table'); | var noHeader = table.classList.contains('no-header-table'); | ||
if (tbody) { | if (tbody) { | ||
// Получаем все строки <tr> внутри первого уровня <tbody> | // Получаем все строки <tr> внутри первого уровня <tbody> | ||
var rows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | var rows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | ||
// Проверяем, что | // Проверяем, что <tr> находится на первом уровне, и исключаем строки с вложенными таблицами | ||
return row.parentElement === tbody && !row.querySelector('table'); | return row.parentElement === tbody && !row.querySelector('table'); | ||
}); | }); | ||
| Строка 365: | Строка 363: | ||
var hasTooManyRowspan = false; | var hasTooManyRowspan = false; | ||
topLevelRows.forEach(function(row) { | topLevelRows.forEach(function(row) { | ||
var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')).filter(function(cell) { | var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')).filter(function(cell) { | ||
return !cell.classList.contains('mobile'); | return !cell.classList.contains('mobile'); | ||
| Строка 373: | Строка 369: | ||
var cellCount = cells.length; | var cellCount = cells.length; | ||
var rowspanCount = cells.filter(function(cell) { | var rowspanCount = cells.filter(function(cell) { | ||
return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1'; | return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1'; | ||
}).length; | }).length; | ||
if (rowspanCount > 2) { | if (rowspanCount > 2) { | ||
hasTooManyRowspan = true; | hasTooManyRowspan = true; | ||
| Строка 384: | Строка 378: | ||
} | } | ||
if (cellCount <= 3 && rowspanCount > 1) { | if (cellCount <= 3 && rowspanCount > 1) { | ||
hasTooManyRowspan = true; | hasTooManyRowspan = true; | ||
| Строка 390: | Строка 383: | ||
} | } | ||
var hasValidRowspanEdge = cells.some(function(cell, index) { | var hasValidRowspanEdge = cells.some(function(cell, index) { | ||
return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1' && (index === 0 || index === cells.length - 1); | return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1' && (index === 0 || index === cells.length - 1); | ||
}); | }); | ||
if (!hasValidRowspanEdge && cells.some(function(cell, index) { | if (!hasValidRowspanEdge && cells.some(function(cell, index) { | ||
return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1' && index > 0 && index < cells.length - 1; | return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1' && index > 0 && index < cells.length - 1; | ||
| Строка 403: | Строка 394: | ||
}); | }); | ||
if (hasTooManyRowspan || hasInvalidRowspan) return; | if (hasTooManyRowspan || hasInvalidRowspan) return; | ||
topLevelRows.forEach(function(row) { | topLevelRows.forEach(function(row) { | ||
var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | ||
var originalStyles = cells.map(function(cell) { | var originalStyles = cells.map(function(cell) { | ||
return { | return { | ||
backgroundColor: getComputedStyle(cell).backgroundColor, | backgroundColor: getComputedStyle(cell).backgroundColor, | ||
| Строка 417: | Строка 405: | ||
}); | }); | ||
cells.forEach(function(cell, index) { | cells.forEach(function(cell, index) { | ||
if (cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1') return; | if (cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1') return; | ||
cell.addEventListener('mouseover', function() { | cell.addEventListener('mouseover', function() { | ||
cells.forEach(function(innerCell, innerIndex) { | cells.forEach(function(innerCell, innerIndex) { | ||
if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') { | if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') { | ||
innerCell.style.setProperty('background-color', brightenColor(originalStyles[innerIndex].backgroundColor), 'important'); | innerCell.style.setProperty('background-color', brightenColor(originalStyles[innerIndex].backgroundColor), 'important'); | ||
innerCell.style.setProperty('color', brightenColor(originalStyles[innerIndex].color), 'important'); | innerCell.style.setProperty('color', brightenColor(originalStyles[innerIndex].color), 'important'); | ||
| Строка 430: | Строка 415: | ||
}); | }); | ||
}); | }); | ||
cell.addEventListener('mouseout', function() { | cell.addEventListener('mouseout', function() { | ||
cells.forEach(function(innerCell, innerIndex) { | cells.forEach(function(innerCell, innerIndex) { | ||
if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') { | if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') { | ||
innerCell.style.setProperty('background-color', originalStyles[innerIndex].backgroundColor, 'important'); | innerCell.style.setProperty('background-color', originalStyles[innerIndex].backgroundColor, 'important'); | ||
innerCell.style.setProperty('color', originalStyles[innerIndex].color, 'important'); | innerCell.style.setProperty('color', originalStyles[innerIndex].color, 'important'); | ||