antonio_pedro

AM4 CheckMoney

Sep 22nd, 2025
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 14.53 KB | Source Code | 0 0
  1. // ==========================================
  2. //  CRIADO POR ANTONIO PEDRO - 2025
  3. // ==========================================
  4.  
  5. (function() {
  6.     'use strict';
  7.  
  8.     // ===================================================================================
  9.     // 1. FUNÇÕES AUXILIARES
  10.     // ===================================================================================
  11.  
  12.     function makeDraggable(element, handle) {
  13.         let offsetX = 0, offsetY = 0, isDragging = false;
  14.         handle.style.cursor = 'move';
  15.         handle.addEventListener('mousedown', (e) => {
  16.             if (e.target.tagName === 'INPUT' || e.target.tagName === 'DATALIST') return;
  17.             isDragging = true;
  18.             offsetX = e.clientX - element.offsetLeft;
  19.             offsetY = e.clientY - element.offsetTop;
  20.             document.addEventListener('mousemove', onMouseMove);
  21.             document.addEventListener('mouseup', onMouseUp);
  22.         });
  23.         function onMouseMove(e) {
  24.             if (!isDragging) return;
  25.             element.style.left = `${e.clientX - offsetX}px`;
  26.             element.style.top = `${e.clientY - offsetY}px`;
  27.             element.style.transform = ''; element.style.right = 'auto'; element.style.bottom = 'auto';
  28.         }
  29.         function onMouseUp() {
  30.             isDragging = false;
  31.             document.removeEventListener('mousemove', onMouseMove);
  32.             document.removeEventListener('mouseup', onMouseUp);
  33.         }
  34.     }
  35.  
  36.     function showFinalMessage(message, isSuccess) {
  37.         const finalMessageContainer = document.createElement('div');
  38.         const borderColor = isSuccess ? '#28a745' : '#dc3545';
  39.         finalMessageContainer.style.cssText = `
  40.             position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  41.             background: white; padding: 30px; border-radius: 10px;
  42.             border: 2px solid ${borderColor}; font-family: Arial, sans-serif;
  43.             box-shadow: 0 5px 25px rgba(0,0,0,0.3); text-align: center; max-width: 400px;
  44.             z-index: 2147483647 !important;
  45.         `;
  46.         finalMessageContainer.innerHTML = `
  47.             <h3 style="margin-top:0; padding-bottom:10px; border-bottom:1px solid #eee;">${isSuccess ? '✅ Sucesso' : '🚨 Alerta'}</h3>
  48.             <p style="margin-top: 20px; margin-bottom: 25px; color: #333; font-size: 18px; line-height: 1.5;">${message}</p>
  49.             <button onclick="this.parentElement.remove()" style="padding: 10px 30px; background: ${borderColor}; color: white;
  50.                                                        border: none; border-radius: 6px; cursor: pointer; font-size: 16px; font-weight: bold;">
  51.                 Fechar
  52.             </button>
  53.         `;
  54.         document.body.appendChild(finalMessageContainer);
  55.         makeDraggable(finalMessageContainer, finalMessageContainer.querySelector('h3'));
  56.     }
  57.  
  58.     function showInputPrompt(callback) {
  59.         const totalPlanesOnPage = document.querySelectorAll('#fleetDetailList .row.border').length;
  60.         if (totalPlanesOnPage === 0) {
  61.             alert("ERRO: Nenhum avião encontrado na página. Verifique se você está na página correta da sua frota ('fleet').");
  62.             return;
  63.         }
  64.         const promptContainer = document.createElement('div');
  65.         promptContainer.id = 'custom-prompt-container';
  66.         promptContainer.style.cssText = `
  67.             position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  68.             background: white; padding: 25px 30px; border-radius: 10px; border: 2px solid #28a745;
  69.             font-family: Arial, sans-serif; box-shadow: 0 5px 25px rgba(0,0,0,0.3); text-align: center; width: 380px;
  70.             z-index: 2147483647 !important;
  71.         `;
  72.         promptContainer.innerHTML = `
  73.             <h3 style="margin-top: 0; margin-bottom: 20px; color: #333; font-size: 20px;">✈️ Configurar Análise de Voos</h3>
  74.             <div style="margin-bottom: 20px; text-align: left;">
  75.                 <label style="display: block; margin-bottom: 5px; color: #555; font-weight: bold;">Valor Base Mínimo:</label>
  76.                 <div id="currentRevenueValue" style="font-size: 18px; font-weight: bold; color: #28a745; margin-bottom: 10px; text-align: center;">$3,000,000</div>
  77.                 <input type="range" id="minRevenueInput" min="0" max="5000000" value="3000000" step="50000" list="revenueTicks" style="width: 100%; cursor: pointer;">
  78.                 <datalist id="revenueTicks"><option value="1000000"></option><option value="2000000"></option><option value="3000000"></option><option value="4000000"></option><option value="5000000"></option></datalist>
  79.             </div>
  80.             <div style="margin-bottom: 25px; text-align: left;">
  81.                 <label style="display: block; margin-bottom: 5px; color: #555; font-weight: bold;">Máximo de Aviões a Analisar:</label>
  82.                 <div id="currentPlanesValue" style="font-size: 18px; font-weight: bold; color: #28a745; margin-bottom: 10px; text-align: center;">${totalPlanesOnPage} aviões</div>
  83.                 <input type="range" id="maxPlanesInput" min="1" max="${totalPlanesOnPage}" value="${totalPlanesOnPage}" step="1" style="width: 100%; cursor: pointer;">
  84.             </div>
  85.             <button id="startAnalysisButton" style="width: 100%; padding: 12px 30px; background: #28a745; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 18px; font-weight: bold;">Iniciar Análise</button>
  86.         `;
  87.         document.body.appendChild(promptContainer);
  88.        
  89.         const revenueSlider = document.getElementById('minRevenueInput');
  90.         const revenueDisplay = document.getElementById('currentRevenueValue');
  91.         const planesSlider = document.getElementById('maxPlanesInput');
  92.         const planesDisplay = document.getElementById('currentPlanesValue');
  93.  
  94.         revenueSlider.addEventListener('input', () => { revenueDisplay.textContent = `$${parseInt(revenueSlider.value).toLocaleString('pt-BR')}`; });
  95.         planesSlider.addEventListener('input', () => { planesDisplay.textContent = `${planesSlider.value} aviões`; });
  96.  
  97.         document.getElementById('startAnalysisButton').onclick = () => {
  98.             const minRevenue = parseInt(revenueSlider.value, 10);
  99.             const maxPlanes = parseInt(planesSlider.value, 10);
  100.             promptContainer.remove();
  101.             callback(minRevenue, maxPlanes);
  102.         };
  103.        
  104.         makeDraggable(promptContainer, promptContainer.querySelector('h3'));
  105.     }
  106.  
  107.     async function startAnalysis(MIN_REVENUE, MAX_PLANES) {
  108.         console.log('🚀 === ANÁLISE DE VOOS - ORDENADA ===');
  109.         console.log(`CONFIGURAÇÕES: Valor Base Mínimo = $${MIN_REVENUE.toLocaleString()}, Máximo de Aviões = ${MAX_PLANES}`);
  110.  
  111.         const progressDiv = document.createElement('div');
  112.         progressDiv.style.cssText = `
  113.             position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  114.             background: white; padding: 20px; border: 2px solid #28a745; border-radius: 10px;
  115.             z-index: 2147483647 !important; font-family: Arial; text-align: center;
  116.             box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  117.         `;
  118.         progressDiv.innerHTML = `<h3>✈️ Analisando Histórico de Voos</h3><div id="progressBar" style="width: 300px; height: 20px; background: #e0e0e0; border-radius: 10px; margin: 10px 0;"><div id="progressFill" style="width: 0%; height: 100%; background: #28a745; border-radius: 10px;"></div></div><div id="progressText">Preparando...</div>`;
  119.         document.body.appendChild(progressDiv);
  120.        
  121.         const updateProgress = (current, total, message = '') => { const percent = (current / total * 100).toFixed(1); const fill = document.getElementById('progressFill'); const text = document.getElementById('progressText'); if(fill) fill.style.width = percent + '%'; if(text) text.textContent = `${current}/${total} (${percent}%) ${message}`; };
  122.         function extractFlightRevenues(detailsHtml) { const patterns = [/\$\s*([\d,]+\.?\d*)/g, /\$\s*([\d,]+)/g, /([\d,]+\.?\d*)\s*\$/g, /(\d{1,3}(?:,\d{3})*(?:\.\d{2})?)/g]; const allValues = []; patterns.forEach(pattern => { let match; while ((match = pattern.exec(detailsHtml)) !== null) { const numStr = match[1].replace(/,/g, ''); const value = parseFloat(numStr); if (!isNaN(value) && value > 100000 && value < 50000000) allValues.push(value); } }); return [...new Set(allValues)].filter(v => v > 500000).sort((a, b) => b - a); }
  123.         async function goBackToList() { const backButtons = document.querySelectorAll('button'); for (let btn of backButtons) { const onclick = btn.getAttribute('onclick') || ''; if (onclick.includes('routesContainer') || onclick.includes('fleetList')) { btn.click(); await new Promise(r => setTimeout(r, 500)); return true; } } return false; }
  124.        
  125.         const rows = document.querySelectorAll('#fleetDetailList .row.border');
  126.         const planes = Array.from(rows).slice(0, MAX_PLANES).map((row) => { const link = row.querySelector('a[href="#"]'); const onclick = link?.getAttribute('onclick') || ''; const idMatch = onclick.match(/id=(\d+)/); return idMatch ? { link, id: idMatch[1], name: link.textContent.trim() } : null; }).filter(Boolean).sort((a, b) => parseInt(a.name.match(/\d{4}$/)[0]) - parseInt(b.name.match(/\d{4}$/)[0]));
  127.        
  128.         updateProgress(0, planes.length, 'Iniciando...');
  129.         const badPlanes = [];
  130.        
  131.         for (let i = 0; i < planes.length; i++) {
  132.             const plane = planes[i];
  133.             updateProgress(i + 1, planes.length, `${plane.name}...`);
  134.             try {
  135.                 plane.link.click();
  136.                 await new Promise(r => setTimeout(r, 1200));
  137.                 const details = document.querySelector('#detailsAction');
  138.                 if (!details || details.innerHTML.trim().length < 200) { await goBackToList(); continue; }
  139.                 const revenues = extractFlightRevenues(details.innerHTML);
  140.                 const last5 = revenues.slice(0, 5);
  141.                 const lowCount = last5.filter(v => v < MIN_REVENUE).length;
  142.                 if (lowCount > 0) { badPlanes.push({ name: plane.name, id: plane.id, lowCount, recentFlights: last5 }); }
  143.                 await goBackToList();
  144.             } catch (e) {
  145.                 console.error(`❌ Erro ${plane.name}: ${e}`);
  146.                 await goBackToList();
  147.             }
  148.         }
  149.        
  150.         progressDiv.remove();
  151.        
  152.         const reportDiv = document.createElement('div');
  153.         // ALTERAÇÃO: Posição inicial centralizada
  154.         reportDiv.style.cssText = `
  155.             position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  156.             background: white; border: 2px solid ${badPlanes.length > 0 ? '#dc3545' : '#28a745'};
  157.             border-radius: 8px; padding: 20px; max-width: 650px; width: 100%;
  158.             max-height: 80vh; display: flex; flex-direction: column;
  159.             box-shadow: 0 4px 20px rgba(0,0,0,0.2); font-family: Arial, sans-serif;
  160.             z-index: 2147483646 !important;
  161.         `;
  162.        
  163.         const minRevenueFormatted = `$${(MIN_REVENUE / 1000000).toFixed(1).replace('.0','')}M`;
  164.         let headerHtml = `<h3 style="margin: 0 0 10px; color: ${badPlanes.length > 0 ? '#dc3545' : '#28a745'};">${badPlanes.length > 0 ? '🚨' : '✅'} Análise de Performance</h3><div style="background: #f8f9fa; padding: 8px; border-radius: 4px; margin-bottom: 10px; font-size: 12px;"><strong>Testados:</strong> ${planes.length} | <strong>Critério:</strong> <span style="color: #dc3545;">${minRevenueFormatted}</span></div>`;
  165.        
  166.         const tableContainer = document.createElement('div');
  167.         tableContainer.style.cssText = 'overflow-y: auto; flex-grow: 1;';
  168.  
  169.         if (badPlanes.length === 0) {
  170.             tableContainer.innerHTML = '<p style="color: #28a745; font-weight: bold; text-align: center; margin-top: 20px;">🎉 Nenhum avião com voos ruins!</p>';
  171.         } else {
  172.             let tableHtml = `<table style="width: 100%; border-collapse: collapse; font-size: 13px;"><thead><tr style="background: #ffebee;"><th style="padding: 10px 8px; text-align: left; border-bottom: 2px solid #dc3545;">Avião</th><th style="padding: 10px 8px; text-align: center; border-bottom: 2px solid #dc3545;">Ruins/5</th><th style="padding: 10px 8px; text-align: right; border-bottom: 2px solid #dc3545;">5 voos recentes</th></tr></thead><tbody>`;
  173.             badPlanes.forEach(plane => {
  174.                 // ALTERAÇÃO: Adiciona cor verde para valores bons e mantém vermelho para ruins
  175.                 const recent5 = plane.recentFlights.map(v => {
  176.                     if (v < MIN_REVENUE) {
  177.                         return `<span style="color: #dc3545; font-weight: bold;">$${v.toLocaleString()}</span>`;
  178.                     } else {
  179.                         return `<span style="color: #28a745;">$${v.toLocaleString()}</span>`;
  180.                     }
  181.                 }).join(' | ');
  182.                
  183.                 tableHtml += `<tr style="border-bottom: 1px solid #eee;"><td style="padding: 10px 8px; font-weight: bold;">${plane.name}</td><td style="padding: 10px 8px; text-align: center; background: #fff3cd; color: #856404; font-weight: bold;">${plane.lowCount}/5</td><td style="padding: 10px 8px; text-align: right; font-size: 12px;">${recent5}</td></tr>`;
  184.             });
  185.             tableHtml += `</tbody></table>`;
  186.             tableContainer.innerHTML = tableHtml;
  187.         }
  188.        
  189.         reportDiv.innerHTML = headerHtml;
  190.         reportDiv.appendChild(tableContainer);
  191.        
  192.         const closeButton = document.createElement('button');
  193.         closeButton.textContent = 'Fechar Relatório';
  194.         closeButton.style.cssText = `padding: 10px 20px; background: #6c757d; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; margin-top: 15px; align-self: center; flex-shrink: 0;`;
  195.         closeButton.onclick = () => reportDiv.remove();
  196.         reportDiv.appendChild(closeButton);
  197.  
  198.         document.body.appendChild(reportDiv);
  199.         makeDraggable(reportDiv, reportDiv.querySelector('h3'));
  200.        
  201.         if (badPlanes.length > 0) {
  202.             showFinalMessage(`Relatório pronto!<br>${badPlanes.length} aviões com voos abaixo do critério.`, false);
  203.         } else {
  204.             showFinalMessage('Análise concluída!<br>Nenhum avião com voos ruins foi encontrado.', true);
  205.         }
  206.     }
  207.  
  208.     // ===================================================================================
  209.     // 3. PONTO DE ENTRADA DO SCRIPT
  210.     // ===================================================================================
  211.     showInputPrompt(startAnalysis);
  212.  
  213. })();
Advertisement
Add Comment
Please, Sign In to add comment