MediaWiki:Common.js: различия между версиями

мНет описания правки
мНет описания правки
Строка 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) {
             factor = 1.045;
             if (r > g && r > b) {
        } else if (brightness < 180) {
                factor = 1.05 + (140 - brightness) / 100; // Красный доминирует
            factor = 1.02;
            } else if (g > r && g > b) {
                factor = 1.05 + (140 - brightness) / 50;  // Зеленый доминирует
            } else {
                factor = 1.05 + (140 - brightness) / 25;   // Темный цвет с доминированием синего
            }
         } else {
         } else {
             factor = 1.0;
             factor = 1.0;
Строка 335: Строка 337:
// Функция для подсветки ячеек в таблице при наведении
// Функция для подсветки ячеек в таблице при наведении
function applyHighlighting() {
function applyHighlighting() {
    // Проверка, является ли устройство мобильным, если да — функция не выполняется
     if (/Mobi|Android/i.test(navigator.userAgent)) {
     if (/Mobi|Android/i.test(navigator.userAgent)) {
         return;
         return;
     }
     }


    // Находим все таблицы с классом 'wikitable', кроме тех, что имеют класс 'no-highlight-table'
     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');
Строка 346: Строка 351:
         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> находится на первом уровне, и исключаем строки с вложенными таблицами
                 // Проверяем, что строка находится на первом уровне (не вложена в другой <tr>)
                 return row.parentElement === tbody && !row.querySelector('table');
                 return row.parentElement === tbody && !row.querySelector('table');
             });
             });
Строка 359: Строка 365:
             var hasTooManyRowspan = false;
             var hasTooManyRowspan = false;


            // Проходим по строкам первого уровня
             topLevelRows.forEach(function(row) {
             topLevelRows.forEach(function(row) {
                // Получаем все ячейки строки, исключая те, что имеют класс 'mobile'
                 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');
Строка 365: Строка 373:
                 var cellCount = cells.length;
                 var cellCount = cells.length;


                // Проверяем, есть ли больше двух ячеек с атрибутом rowspan
                 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;


                // Если в строке больше двух ячеек с rowspan, функция не применяется
                 if (rowspanCount > 2) {
                 if (rowspanCount > 2) {
                     hasTooManyRowspan = true;
                     hasTooManyRowspan = true;
Строка 374: Строка 384:
                 }
                 }


                // Если строка имеет 3 или меньше ячеек и больше одного rowspan, не применяем функцию
                 if (cellCount <= 3 && rowspanCount > 1) {
                 if (cellCount <= 3 && rowspanCount > 1) {
                     hasTooManyRowspan = true;
                     hasTooManyRowspan = true;
Строка 379: Строка 390:
                 }
                 }


                // Проверяем, есть ли корректные ячейки с rowspan на краю строки (первый или последний элемент)
                 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);
                 });
                 });


                // Если ячейки с rowspan находятся не на краю, устанавливаем флаг ошибки
                 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;
Строка 390: Строка 403:
             });
             });


            // Если есть некорректные строки с rowspan или слишком много rowspan, выходим
             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,
Строка 401: Строка 417:
                 });
                 });


                // Добавляем события 'mouseover' и 'mouseout' для подсветки
                 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');
Строка 411: Строка 430:
                         });
                         });
                     });
                     });
                    // Добавляем обработчик события, когда мышь уходит с ячейки
                     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');