// ==UserScript== // @name https://github.com/derazo75 - Generation Apps ordering // @namespace http://tampermonkey.net/ // @version 1.1 // @description Menu contextual con clic derecho sobre la tabla para ordenar por fecha/hora descendente // @author You // @match http://*/scriptcase/devel/iface/open_app.php* // @grant none // ==/UserScript== (function() { 'use strict'; // 1. Función principal de ordenamiento function ordenarPorFechaGeneracion() { const table = document.querySelector('table.nmTableAppList'); if (!table) { alert('No se encontró la tabla de aplicaciones.'); return; } const tbody = table.querySelector('tbody'); const appRows = Array.from(tbody.querySelectorAll('tr.classApps, tr.cls_tr_app')).filter(r => !r.id?.includes('id_folder')); if (appRows.length === 0) { alert('No hay filas de aplicaciones para ordenar.'); return; } const items = []; appRows.forEach((mainRow) => { let dateText = ''; // Buscar texto con formato MM/DD/YY HH:mm dentro de las celdas o spans de la fila Array.from(mainRow.cells).forEach(cell => { const match = cell.innerText.trim().match(/(\d{2})\/(\d{2})\/(\d{2})\s+(\d{2}):(\d{2})/); if (match) { dateText = match[0]; } }); if (!dateText) { const spans = mainRow.querySelectorAll('span, a, div'); spans.forEach(el => { const match = el.innerText.trim().match(/(\d{2})\/(\d{2})\/(\d{2})\s+(\d{2}):(\d{2})/); if (match) { dateText = match[0]; } }); } const match = dateText.match(/(\d{2})\/(\d{2})\/(\d{2})\s+(\d{2}):(\d{2})/); let timestamp = 0; if (match) { const month = parseInt(match[1], 10) - 1; const day = parseInt(match[2], 10); const year = parseInt(match[3], 10) + 2000; const hour = parseInt(match[4], 10); const minute = parseInt(match[5], 10); timestamp = new Date(year, month, day, hour, minute).getTime(); } let dataRow = null; let lineRow = null; let next = mainRow.nextElementSibling; if (next && !next.classList.contains('classApps') && !next.classList.contains('cls_tr_app')) { dataRow = next; next = next.nextElementSibling; } if (next && next.classList.contains('nmTableLine')) { lineRow = next; } items.push({ mainRow, dataRow, lineRow, timestamp }); }); // Ordenar de mayor a menor timestamp (DESC) items.sort((a, b) => b.timestamp - a.timestamp); // Reinsertar en el DOM items.forEach(item => { tbody.appendChild(item.mainRow); if (item.dataRow) { tbody.appendChild(item.dataRow); } if (item.lineRow) { tbody.appendChild(item.lineRow); } }); console.log('¡Tabla ordenada por generationDate DESC!'); } // 2. Inyectar estilos CSS para evitar advertencias de ESLint const style = document.createElement('style'); style.textContent = ` #sc-sort-btn { position: fixed; top: 0px; right: 10px; z-index: 999999; background-color: #2b579a; color: #ffffff; border: none; border-radius: 4px; padding: 4px 14px; font-family: Arial, sans-serif; font-size: 10px; font-weight: bold; cursor: pointer; box-shadow: 0px 2px 6px rgba(0,0,0,0.25); transition: background-color 0.2s, transform 0.1s; } #sc-sort-btn:hover { background-color: #1a3866; } #sc-sort-btn:active { transform: scale(0.96); } `; document.head.appendChild(style); // 3. Crear el botón flotante const btn = document.createElement('button'); btn.id = 'sc-sort-btn'; btn.innerHTML = '⚡ ORDER BY GENERATION DESC'; btn.addEventListener('click', ordenarPorFechaGeneracion); document.body.appendChild(btn); })();