Logo
Sistema de Gestión de Equipos
Creado por Andres Florez - Analista MTTO
) document.addEventListener('DOMContentLoaded', function() { // Selección múltiple de repuestos en el modal const selectAllSpareParts = document.getElementById('selectAllSpareParts'); if (selectAllSpareParts) { selectAllSpareParts.addEventListener('change', function() { const checkboxes = document.querySelectorAll('#sparePartsTableBody input[type="checkbox"]'); checkboxes.forEach(cb => { cb.checked = selectAllSpareParts.checked; }); }); } // Si se desmarca manualmente algún checkbox, desmarcar el "select all" const sparePartsTableBody = document.getElementById('sparePartsTableBody'); if (sparePartsTableBody) { sparePartsTableBody.addEventListener('change', function(e) { if (e.target.type === 'checkbox') { const all = document.querySelectorAll('#sparePartsTableBody input[type="checkbox"]'); const checked = document.querySelectorAll('#sparePartsTableBody input[type="checkbox"]:checked'); const selectAll = document.getElementById('selectAllSpareParts'); if (selectAll) { selectAll.checked = (all.length === checked.length); } } }); } // Configurar event listeners del dashboard si está visible setTimeout(() => { if (document.getElementById('mainMenuPage') && !document.getElementById('mainMenuPage').classList.contains('hidden')) { setupDashboardEventListeners(); } // Configurar event listeners de la página de lista si está visible if (document.getElementById('listPage') && !document.getElementById('listPage').classList.contains('hidden')) { setupListPageEventListeners(); } }, 100); }); // Exponer funciones necesarias para la pantalla de acceso directo por QR window.downloadMaintenanceReport = downloadMaintenanceReport; window.openMaintenanceModal = openMaintenanceModal; // SOLUCIÓN DEFINITIVA: Eliminar cualquier código JavaScript visible function removeVisibleJavaScript() { console.log('🔍 Buscando código JavaScript visible...'); // Buscar y eliminar nodos de texto que contengan código JavaScript const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_TEXT, null, false ); const nodesToRemove = []; let node; while (node = walker.nextNode()) { const text = node.textContent.trim(); if (text.length > 20 && ( text.includes('document.addEventListener') || text.includes('DOMContentLoaded') || text.includes('getElementById') || text.includes('querySelector') || text.includes('addEventListener') || text.includes('function(') || text.includes('const ') || text.includes('let ') || text.includes('var ') || text.includes('if (') || text.includes('forEach') || text.includes('setTimeout') || text.includes('setInterval') || text.includes('classList') || text.includes('style.') || text.includes('innerHTML') || text.includes('textContent') || text.includes('parentNode') || text.includes('removeChild') || text.includes('appendChild') || text.includes('createTreeWalker') || text.includes('NodeFilter') || text.includes('MutationObserver') || (text.includes('document.') && text.includes('=')) || (text.includes('{') && text.includes('}') && text.length > 50) )) { console.log('🗑️ Eliminando nodo con código JavaScript:', text.substring(0, 80)); nodesToRemove.push(node); } } // Eliminar los nodos encontrados nodesToRemove.forEach(node => { if (node.parentNode && node.parentNode.tagName !== 'SCRIPT' && node.parentNode.tagName !== 'STYLE') { node.parentNode.removeChild(node); } }); // También buscar elementos que contengan solo código JavaScript const allElements = document.querySelectorAll('*:not(script):not(style)'); allElements.forEach(element => { if (element.childNodes.length === 1 && element.childNodes[0].nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text.length > 100 && ( text.includes('document.addEventListener') || text.includes('getElementById') || text.includes('DOMContentLoaded') || text.includes('function(') || text.includes('const ') || text.includes('addEventListener') )) { console.log('🗑️ Eliminando elemento con código JavaScript:', element.tagName, text.substring(0, 80)); element.remove(); } } }); console.log('✅ Limpieza completada'); } // Ejecutar limpieza inmediatamente y cada 500ms removeVisibleJavaScript(); setInterval(removeVisibleJavaScript, 500); // Observer para detectar nuevos nodos agregados dinámicamente const observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'childList') { mutation.addedNodes.forEach(function(node) { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent.trim(); if (text.length > 20 && ( text.includes('document.addEventListener') || text.includes('getElementById') || text.includes('DOMContentLoaded') || text.includes('function(') || text.includes('const ') || text.includes('addEventListener') )) { console.log('🚫 Eliminando nodo agregado dinámicamente:', text.substring(0, 60)); if (node.parentNode) { node.parentNode.removeChild(node); } } } }); } }); }); // Observar cambios en todo el documento observer.observe(document.body, { childList: true, subtree: true }); // Interceptar métodos DOM para prevenir la adición de código JavaScript const originalAppendChild = Element.prototype.appendChild; const originalInsertBefore = Element.prototype.insertBefore; const originalInnerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML'); Element.prototype.appendChild = function(node) { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent.trim(); if (text.length > 20 && ( text.includes('document.addEventListener') || text.includes('getElementById') || text.includes('DOMContentLoaded') || text.includes('function(') || text.includes('const ') || text.includes('addEventListener') )) { console.log('🚫 Interceptando appendChild de código JavaScript:', text.substring(0, 60)); return node; // No agregarlo } } return originalAppendChild.call(this, node); }; Element.prototype.insertBefore = function(node, referenceNode) { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent.trim(); if (text.length > 20 && ( text.includes('document.addEventListener') || text.includes('getElementById') || text.includes('DOMContentLoaded') || text.includes('function(') || text.includes('const ') || text.includes('addEventListener') )) { console.log('🚫 Interceptando insertBefore de código JavaScript:', text.substring(0, 60)); return node; // No agregarlo } } return originalInsertBefore.call(this, node, referenceNode); }; // Interceptar innerHTML if (originalInnerHTML) { Object.defineProperty(Element.prototype, 'innerHTML', { set: function(value) { if (typeof value === 'string' && value.length > 100 && ( value.includes('document.addEventListener') || value.includes('getElementById') || value.includes('DOMContentLoaded') || value.includes('function(') || value.includes('const ') || value.includes('addEventListener') )) { console.log('🚫 Interceptando innerHTML con código JavaScript:', value.substring(0, 80)); return; // No permitir } return originalInnerHTML.set.call(this, value); }, get: originalInnerHTML.get }); } // Limpiar inmediatamente al cargar document.addEventListener('DOMContentLoaded', function() { setTimeout(removeVisibleJavaScript, 100); }); window.addEventListener('load', function() { setTimeout(removeVisibleJavaScript, 200); }); // Función para limpiar cualquier código JavaScript visible function cleanupVisibleJavaScript() { try { // Buscar y eliminar cualquier nodo de texto que contenga código JavaScript const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_TEXT, null, false ); const textNodesToRemove = []; let node; while (node = walker.nextNode()) { const text = node.textContent.trim(); if (text.length > 20 && ( text.includes('document.addEventListener') || text.includes('DOMContentLoaded') || text.includes('function()') || text.includes('getElementById') || text.includes('addEventListener') || text.includes('querySelector') || text.includes('document.get') || text.includes('const ') || text.includes('let ') || text.includes('var ') || text.includes('if (') || text.includes('forEach') || text.includes('.style.') || text.includes('.classList.') || text.includes('function(') || (text.includes('document.') && text.length > 50) || (text.includes('{') && text.includes('}') && text.length > 100) )) { textNodesToRemove.push(node); } } textNodesToRemove.forEach(node => { if (node.parentNode && node.parentNode.tagName !== 'SCRIPT' && node.parentNode.tagName !== 'STYLE') { console.log('Eliminando nodo de texto con código JavaScript:', node.textContent.substring(0, 100)); node.parentNode.removeChild(node); } }); // También buscar elementos que puedan contener código JavaScript como contenido const allElements = document.querySelectorAll('*:not(script):not(style)'); allElements.forEach(element => { if (element.childNodes.length === 1 && element.childNodes[0].nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text.length > 50 && ( text.includes('document.addEventListener') || text.includes('DOMContentLoaded') || text.includes('getElementById') || text.includes('addEventListener') || text.includes('querySelector') || text.includes('function(') || (text.includes('{') && text.includes('}') && text.includes('document.')) )) { console.log('Eliminando elemento con código JavaScript:', element.tagName, text.substring(0, 100)); element.style.display = 'none'; element.remove(); } } }); } catch (error) { console.log('Error en limpieza de JavaScript:', error); } } // Función más agresiva para limpiar al final del body function cleanupEndOfBody() { try { const bodyChildren = Array.from(document.body.children); bodyChildren.forEach((child, index) => { // Si es uno de los últimos elementos y contiene mucho texto que parece código if (index >= bodyChildren.length - 3) { const text = child.textContent || ''; if (text.length > 100 && ( text.includes('document.addEventListener') || text.includes('getElementById') || text.includes('addEventListener') || text.includes('DOMContentLoaded') )) { console.log('Eliminando elemento al final del body:', child.tagName, text.substring(0, 100)); child.remove(); } } }); } catch (error) { console.log('Error en limpieza del final del body:', error); } } // Función para eliminar inmediatamente cualquier nodo de texto sospechoso function immediateCleanup() { // Eliminar cualquier nodo de texto directamente en el body const bodyChildren = Array.from(document.body.childNodes); bodyChildren.forEach(node => { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent.trim(); if (text.length > 10 && ( text.includes('document') || text.includes('addEventListener') || text.includes('function') || text.includes('const ') || text.includes('let ') || text.includes('var ') || text.includes('getElementById') )) { console.log('Eliminando nodo de texto directo en body:', text.substring(0, 50)); document.body.removeChild(node); } } }); } // Ejecutar limpieza inmediatamente y muy frecuentemente immediateCleanup(); setTimeout(cleanupVisibleJavaScript, 50); setTimeout(cleanupEndOfBody, 100); setTimeout(immediateCleanup, 150); // Ejecutar limpieza muy frecuentemente setInterval(immediateCleanup, 500); setInterval(cleanupVisibleJavaScript, 1000); setInterval(cleanupEndOfBody, 1500); // Observer para detectar nuevos nodos agregados const observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'childList') { mutation.addedNodes.forEach(function(node) { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent.trim(); if (text.length > 10 && ( text.includes('document.addEventListener') || text.includes('getElementById') || text.includes('addEventListener') || text.includes('DOMContentLoaded') || text.includes('function(') || text.includes('const ') || text.includes('let ') || text.includes('var ') || text.includes('document.get') || text.includes('querySelector') )) { console.log('Eliminando nodo de texto agregado dinámicamente:', text.substring(0, 50)); if (node.parentNode) { node.parentNode.removeChild(node); } } } else if (node.nodeType === Node.ELEMENT_NODE) { // Si es un elemento, verificar si contiene solo texto de código const text = node.textContent?.trim() || ''; if (text.length > 100 && ( text.includes('document.addEventListener') || text.includes('getElementById') || text.includes('DOMContentLoaded') )) { console.log('Eliminando elemento agregado dinámicamente con código:', node.tagName, text.substring(0, 50)); if (node.parentNode) { node.parentNode.removeChild(node); } } } }); } }); }); // Observar cambios en el body observer.observe(document.body, { childList: true, subtree: true }); // Interceptar cualquier intento de agregar contenido al body const originalAppendChild = document.body.appendChild; const originalInsertBefore = document.body.insertBefore; document.body.appendChild = function(node) { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent.trim(); if (text.length > 10 && ( text.includes('document') || text.includes('addEventListener') || text.includes('function') || text.includes('const ') || text.includes('getElementById') )) { console.log('Interceptando appendChild de nodo de texto con código:', text.substring(0, 50)); return node; // No agregarlo } } return originalAppendChild.call(this, node); }; document.body.insertBefore = function(node, referenceNode) { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent.trim(); if (text.length > 10 && ( text.includes('document') || text.includes('addEventListener') || text.includes('function') || text.includes('const ') || text.includes('getElementById') )) { console.log('Interceptando insertBefore de nodo de texto con código:', text.substring(0, 50)); return node; // No agregarlo } } return originalInsertBefore.call(this, node, referenceNode); }; // Limpiar inmediatamente al cargar la página document.addEventListener('DOMContentLoaded', function() { immediateCleanup(); cleanupVisibleJavaScript(); cleanupEndOfBody(); }); // También limpiar cuando la página esté completamente cargada window.addEventListener('load', function() { setTimeout(immediateCleanup, 100); setTimeout(cleanupVisibleJavaScript, 200); setTimeout(cleanupEndOfBody, 300); }); // Función para configurar la búsqueda function setupSearchFunction() { console.log('🔧 Configurando función de búsqueda...'); const searchEquipos = document.getElementById('searchEquipos'); console.log('🔍 Elemento searchEquipos encontrado:', searchEquipos); if (searchEquipos) { // Remover event listeners previos searchEquipos.removeEventListener('input', handleSearch); searchEquipos.removeEventListener('keyup', handleSearch); searchEquipos.removeEventListener('change', handleSearch); // Agregar múltiples event listeners para asegurar que funcione searchEquipos.addEventListener('input', handleSearch); searchEquipos.addEventListener('keyup', handleSearch); searchEquipos.addEventListener('change', handleSearch); // Probar que el event listener funciona console.log('✅ Event listeners de búsqueda configurados'); console.log('🧪 Probando event listener...'); // Simular un evento de prueba setTimeout(() => { if (searchEquipos.value) { console.log('🔄 Ejecutando búsqueda inicial...'); handleSearch.call(searchEquipos); } }, 100); } else { console.error('❌ Elemento searchEquipos no encontrado'); } } // Función manejadora de la búsqueda function handleSearch() { const searchTerm = this.value.toLowerCase().trim(); console.log('🔍 Búsqueda iniciada. Término:', searchTerm); const machineItems = document.querySelectorAll('.machine-item'); console.log('📋 Elementos machine-item encontrados:', machineItems.length); let foundCount = 0; if (machineItems.length === 0) { console.warn('⚠️ No se encontraron elementos .machine-item'); return; } machineItems.forEach((item, index) => { // Obtener todo el texto del elemento const itemText = item.textContent.toLowerCase(); console.log(`📄 Elemento ${index + 1}:`, itemText.substring(0, 150) + '...'); // Verificar si el término de búsqueda está en el texto const matches = itemText.includes(searchTerm); console.log(`🔍 Coincidencia para elemento ${index + 1}:`, matches); if (matches) { item.style.display = ''; foundCount++; // Resaltar si hay término de búsqueda if (searchTerm.length > 0) { item.style.border = '2px solid #2476d2'; item.style.backgroundColor = '#f0f8ff'; } console.log(`✅ Elemento ${index + 1} mostrado`); } else { item.style.display = 'none'; item.style.border = ''; item.style.backgroundColor = ''; console.log(`❌ Elemento ${index + 1} oculto`); } }); // Actualizar contador const searchResults = document.getElementById('searchResults'); const searchCount = document.getElementById('searchCount'); if (searchResults && searchCount) { searchCount.textContent = foundCount; searchResults.style.display = searchTerm.length > 0 ? 'block' : 'none'; } console.log(`📊 Resultado: Encontrados ${foundCount} de ${machineItems.length} equipos`); } // Función de prueba para verificar la búsqueda manualmente function testSearch(searchTerm = 'LLBL76-81E') { console.log('🧪 Iniciando prueba de búsqueda manual...'); console.log('🔍 Término de búsqueda:', searchTerm); const machineItems = document.querySelectorAll('.machine-item'); console.log('📋 Total de elementos encontrados:', machineItems.length); if (machineItems.length === 0) { console.error('❌ No se encontraron elementos .machine-item'); return; } let foundCount = 0; machineItems.forEach((item, index) => { const itemText = item.textContent.toLowerCase(); const matches = itemText.includes(searchTerm.toLowerCase()); if (matches) { foundCount++; console.log(`✅ Elemento ${index + 1} coincide:`, itemText.substring(0, 100) + '...'); } }); console.log(`📊 Prueba completada: ${foundCount} elementos coinciden con "${searchTerm}"`); // Ejecutar la búsqueda real const searchInput = document.getElementById('searchEquipos'); if (searchInput) { searchInput.value = searchTerm; handleSearch.call(searchInput); } } // Exponer la función de prueba globalmente window.testSearch = testSearch;