Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==========================================
- // CRIADO POR ANTONIO PEDRO - 2025
- // ==========================================
- (function() {
- 'use strict';
- // ===================================================================================
- // 1. FUNÇÕES AUXILIARES
- // ===================================================================================
- function makeDraggable(element, handle) {
- let offsetX = 0, offsetY = 0, isDragging = false;
- handle.style.cursor = 'move';
- handle.addEventListener('mousedown', (e) => {
- if (e.target.tagName === 'INPUT' || e.target.tagName === 'DATALIST') return;
- isDragging = true;
- offsetX = e.clientX - element.offsetLeft;
- offsetY = e.clientY - element.offsetTop;
- document.addEventListener('mousemove', onMouseMove);
- document.addEventListener('mouseup', onMouseUp);
- });
- function onMouseMove(e) {
- if (!isDragging) return;
- element.style.left = `${e.clientX - offsetX}px`;
- element.style.top = `${e.clientY - offsetY}px`;
- element.style.transform = ''; element.style.right = 'auto'; element.style.bottom = 'auto';
- }
- function onMouseUp() {
- isDragging = false;
- document.removeEventListener('mousemove', onMouseMove);
- document.removeEventListener('mouseup', onMouseUp);
- }
- }
- function showFinalMessage(message, isSuccess) {
- const finalMessageContainer = document.createElement('div');
- const borderColor = isSuccess ? '#28a745' : '#dc3545';
- finalMessageContainer.style.cssText = `
- position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
- background: white; padding: 30px; border-radius: 10px;
- border: 2px solid ${borderColor}; font-family: Arial, sans-serif;
- box-shadow: 0 5px 25px rgba(0,0,0,0.3); text-align: center; max-width: 400px;
- z-index: 2147483647 !important;
- `;
- finalMessageContainer.innerHTML = `
- <h3 style="margin-top:0; padding-bottom:10px; border-bottom:1px solid #eee;">${isSuccess ? '✅ Sucesso' : '🚨 Alerta'}</h3>
- <p style="margin-top: 20px; margin-bottom: 25px; color: #333; font-size: 18px; line-height: 1.5;">${message}</p>
- <button onclick="this.parentElement.remove()" style="padding: 10px 30px; background: ${borderColor}; color: white;
- border: none; border-radius: 6px; cursor: pointer; font-size: 16px; font-weight: bold;">
- Fechar
- </button>
- `;
- document.body.appendChild(finalMessageContainer);
- makeDraggable(finalMessageContainer, finalMessageContainer.querySelector('h3'));
- }
- function showInputPrompt(callback) {
- const totalPlanesOnPage = document.querySelectorAll('#fleetDetailList .row.border').length;
- if (totalPlanesOnPage === 0) {
- alert("ERRO: Nenhum avião encontrado na página. Verifique se você está na página correta da sua frota ('fleet').");
- return;
- }
- const promptContainer = document.createElement('div');
- promptContainer.id = 'custom-prompt-container';
- promptContainer.style.cssText = `
- position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
- background: white; padding: 25px 30px; border-radius: 10px; border: 2px solid #28a745;
- font-family: Arial, sans-serif; box-shadow: 0 5px 25px rgba(0,0,0,0.3); text-align: center; width: 380px;
- z-index: 2147483647 !important;
- `;
- promptContainer.innerHTML = `
- <h3 style="margin-top: 0; margin-bottom: 20px; color: #333; font-size: 20px;">✈️ Configurar Análise de Voos</h3>
- <div style="margin-bottom: 20px; text-align: left;">
- <label style="display: block; margin-bottom: 5px; color: #555; font-weight: bold;">Valor Base Mínimo:</label>
- <div id="currentRevenueValue" style="font-size: 18px; font-weight: bold; color: #28a745; margin-bottom: 10px; text-align: center;">$3,000,000</div>
- <input type="range" id="minRevenueInput" min="0" max="5000000" value="3000000" step="50000" list="revenueTicks" style="width: 100%; cursor: pointer;">
- <datalist id="revenueTicks"><option value="1000000"></option><option value="2000000"></option><option value="3000000"></option><option value="4000000"></option><option value="5000000"></option></datalist>
- </div>
- <div style="margin-bottom: 25px; text-align: left;">
- <label style="display: block; margin-bottom: 5px; color: #555; font-weight: bold;">Máximo de Aviões a Analisar:</label>
- <div id="currentPlanesValue" style="font-size: 18px; font-weight: bold; color: #28a745; margin-bottom: 10px; text-align: center;">${totalPlanesOnPage} aviões</div>
- <input type="range" id="maxPlanesInput" min="1" max="${totalPlanesOnPage}" value="${totalPlanesOnPage}" step="1" style="width: 100%; cursor: pointer;">
- </div>
- <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>
- `;
- document.body.appendChild(promptContainer);
- const revenueSlider = document.getElementById('minRevenueInput');
- const revenueDisplay = document.getElementById('currentRevenueValue');
- const planesSlider = document.getElementById('maxPlanesInput');
- const planesDisplay = document.getElementById('currentPlanesValue');
- revenueSlider.addEventListener('input', () => { revenueDisplay.textContent = `$${parseInt(revenueSlider.value).toLocaleString('pt-BR')}`; });
- planesSlider.addEventListener('input', () => { planesDisplay.textContent = `${planesSlider.value} aviões`; });
- document.getElementById('startAnalysisButton').onclick = () => {
- const minRevenue = parseInt(revenueSlider.value, 10);
- const maxPlanes = parseInt(planesSlider.value, 10);
- promptContainer.remove();
- callback(minRevenue, maxPlanes);
- };
- makeDraggable(promptContainer, promptContainer.querySelector('h3'));
- }
- async function startAnalysis(MIN_REVENUE, MAX_PLANES) {
- console.log('🚀 === ANÁLISE DE VOOS - ORDENADA ===');
- console.log(`CONFIGURAÇÕES: Valor Base Mínimo = $${MIN_REVENUE.toLocaleString()}, Máximo de Aviões = ${MAX_PLANES}`);
- const progressDiv = document.createElement('div');
- progressDiv.style.cssText = `
- position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
- background: white; padding: 20px; border: 2px solid #28a745; border-radius: 10px;
- z-index: 2147483647 !important; font-family: Arial; text-align: center;
- box-shadow: 0 4px 20px rgba(0,0,0,0.3);
- `;
- 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>`;
- document.body.appendChild(progressDiv);
- 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}`; };
- 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); }
- 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; }
- const rows = document.querySelectorAll('#fleetDetailList .row.border');
- 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]));
- updateProgress(0, planes.length, 'Iniciando...');
- const badPlanes = [];
- for (let i = 0; i < planes.length; i++) {
- const plane = planes[i];
- updateProgress(i + 1, planes.length, `${plane.name}...`);
- try {
- plane.link.click();
- await new Promise(r => setTimeout(r, 1200));
- const details = document.querySelector('#detailsAction');
- if (!details || details.innerHTML.trim().length < 200) { await goBackToList(); continue; }
- const revenues = extractFlightRevenues(details.innerHTML);
- const last5 = revenues.slice(0, 5);
- const lowCount = last5.filter(v => v < MIN_REVENUE).length;
- if (lowCount > 0) { badPlanes.push({ name: plane.name, id: plane.id, lowCount, recentFlights: last5 }); }
- await goBackToList();
- } catch (e) {
- console.error(`❌ Erro ${plane.name}: ${e}`);
- await goBackToList();
- }
- }
- progressDiv.remove();
- const reportDiv = document.createElement('div');
- // ALTERAÇÃO: Posição inicial centralizada
- reportDiv.style.cssText = `
- position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
- background: white; border: 2px solid ${badPlanes.length > 0 ? '#dc3545' : '#28a745'};
- border-radius: 8px; padding: 20px; max-width: 650px; width: 100%;
- max-height: 80vh; display: flex; flex-direction: column;
- box-shadow: 0 4px 20px rgba(0,0,0,0.2); font-family: Arial, sans-serif;
- z-index: 2147483646 !important;
- `;
- const minRevenueFormatted = `$${(MIN_REVENUE / 1000000).toFixed(1).replace('.0','')}M`;
- 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>`;
- const tableContainer = document.createElement('div');
- tableContainer.style.cssText = 'overflow-y: auto; flex-grow: 1;';
- if (badPlanes.length === 0) {
- tableContainer.innerHTML = '<p style="color: #28a745; font-weight: bold; text-align: center; margin-top: 20px;">🎉 Nenhum avião com voos ruins!</p>';
- } else {
- 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>`;
- badPlanes.forEach(plane => {
- // ALTERAÇÃO: Adiciona cor verde para valores bons e mantém vermelho para ruins
- const recent5 = plane.recentFlights.map(v => {
- if (v < MIN_REVENUE) {
- return `<span style="color: #dc3545; font-weight: bold;">$${v.toLocaleString()}</span>`;
- } else {
- return `<span style="color: #28a745;">$${v.toLocaleString()}</span>`;
- }
- }).join(' | ');
- 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>`;
- });
- tableHtml += `</tbody></table>`;
- tableContainer.innerHTML = tableHtml;
- }
- reportDiv.innerHTML = headerHtml;
- reportDiv.appendChild(tableContainer);
- const closeButton = document.createElement('button');
- closeButton.textContent = 'Fechar Relatório';
- 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;`;
- closeButton.onclick = () => reportDiv.remove();
- reportDiv.appendChild(closeButton);
- document.body.appendChild(reportDiv);
- makeDraggable(reportDiv, reportDiv.querySelector('h3'));
- if (badPlanes.length > 0) {
- showFinalMessage(`Relatório pronto!<br>${badPlanes.length} aviões com voos abaixo do critério.`, false);
- } else {
- showFinalMessage('Análise concluída!<br>Nenhum avião com voos ruins foi encontrado.', true);
- }
- }
- // ===================================================================================
- // 3. PONTO DE ENTRADA DO SCRIPT
- // ===================================================================================
- showInputPrompt(startAnalysis);
- })();
Advertisement
Add Comment
Please, Sign In to add comment