Formulario Helper

Formulario Helper para chamados.

当前为 2025-05-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         Formulario Helper
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Formulario Helper para chamados.
// @author       ils94
// @match        https://atendimento-sao.tre-rn.jus.br/front/tracking.injector.php
// @grant        GM_setClipboard
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function criarModal() {
        const estilo = `
        #formModal {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 20px;
            border: 2px solid #007bff;
            border-radius: 10px;
            z-index: 10000;
            box-shadow: 0 0 10px rgba(0,0,0,0.5);
            width: 300px;
            font-family: sans-serif;
        }
        #formModal input, #formModal select, #formModal textarea {
            width: 100%;
            margin-bottom: 10px;
            padding: 5px;
            font-size: 14px;
            box-sizing: border-box;
        }
        #formModal textarea {
            resize: vertical;
            min-height: 60px;
            max-height: 120px;
        }
        #formModal .linha-flex {
            display: flex;
            gap: 5px;
            align-items: stretch;
        }
        #formModal button {
            margin-top: 5px;
            padding: 8px;
            width: 100%;
            font-weight: bold;
            cursor: pointer;
        }
        #fecharModal {
            position: absolute;
            top: 5px;
            right: 10px;
            cursor: pointer;
            font-weight: bold;
            color: red;
        }
    `;

        const styleTag = document.createElement('style');
        styleTag.textContent = estilo;
        document.head.appendChild(styleTag);

        const modal = document.createElement('div');
        modal.id = 'formModal';
        modal.style.display = 'none';

        const {
            data,
            hora
        } = obterDataHoraAtual();

        modal.innerHTML = `
        <span id="fecharModal">X</span>
        <label>Data:</label><input id="data" value="${data}">
        <label>Hora:</label><input id="hora" value="${hora}">
        <label>Origem:</label>
        <select id="origem">
            <option value="COJE">COJE</option>
            <option value="SEDE">SEDE</option>
        </select>
        <label>Destino:</label>
        <select id="destino">
            <option value="SEDE">SEDE</option>
            <option value="COJE">COJE</option>
        </select>
        <label>Passageiros:</label><input id="passageiros" placeholder="NOME1, NOME2">
        <label>Prioridade:</label>
        <select id="prioridade">
            <option value="NORMAL">NORMAL</option>
            <option value="URGENTE">URGENTE</option>
        </select>
        <label>Necessidade Especial:</label><input id="especial" placeholder="NENHUMA">
        <label>Justificativa do Chamado:</label><textarea id="justificativa" placeholder="Digite a justificativa aqui..."></textarea>
        <button id="copiarTexto">Copiar para área de transferência</button>
    `;

        document.body.appendChild(modal);

        document.getElementById('fecharModal').onclick = () => modal.style.display = 'none';

        // Sincronizar selects de origem e destino
        const origemSelect = modal.querySelector('#origem');
        const destinoSelect = modal.querySelector('#destino');

        origemSelect.addEventListener('change', () => {
            destinoSelect.value = origemSelect.value === 'COJE' ? 'SEDE' : 'COJE';
        });

        destinoSelect.addEventListener('change', () => {
            origemSelect.value = destinoSelect.value === 'COJE' ? 'SEDE' : 'COJE';
        });

        document.getElementById('copiarTexto').onclick = () => {
            const especialInput = document.getElementById('especial').value.trim();
            const especialTexto = especialInput === '' ? 'NENHUMA' : especialInput;
            const justificativaInput = document.getElementById('justificativa').value.trim();
            const justificativaTexto = justificativaInput === '' ? 'NENHUMA' : justificativaInput;

            const texto = `
DATA: ${document.getElementById('data').value}
HORA: ${document.getElementById('hora').value}
ORIGEM: ${document.getElementById('origem').value}
DESTINO: ${document.getElementById('destino').value}
NOME DOS PASSAGEIROS: ${document.getElementById('passageiros').value}
PRIORIDADE: ${document.getElementById('prioridade').value}
NECESSIDADE ESPECIAL: ${especialTexto}
JUSTIFICATIVA DO CHAMADO: ${justificativaTexto}
        `.trim().toUpperCase();

            if (typeof GM_setClipboard !== 'undefined') {
                GM_setClipboard(texto);
            } else {
                navigator.clipboard.writeText(texto).then(() => alert('Copiado!'));
            }

            document.getElementById('formModal').style.display = 'none';
        };
    }


    function criarBotao() {
        const doc = window.top.document; // documento da janela principal, não do iframe
        // Remove o botão se já existir
        const botaoExistente = doc.getElementById('botaoGerarSolicitacao');
        if (botaoExistente) botaoExistente.remove();

        const botao = doc.createElement('button');
        botao.id = 'botaoGerarSolicitacao';
        botao.textContent = 'Gerar Solicitação';
        botao.style.position = 'fixed';
        botao.style.bottom = '20px';
        botao.style.right = '20px';
        botao.style.padding = '10px 15px';
        botao.style.backgroundColor = '#007bff';
        botao.style.color = '#fff';
        botao.style.border = 'none';
        botao.style.borderRadius = '5px';
        botao.style.cursor = 'pointer';
        botao.style.zIndex = '9999';
        botao.onclick = () => doc.getElementById('formModal').style.display = 'block';

        doc.body.appendChild(botao);
    }



    function obterDataHoraAtual() {
        const agora = new Date();
        const data = agora.toLocaleDateString('pt-BR');
        const hora = agora.toLocaleTimeString('pt-BR', {
            hour: '2-digit',
            minute: '2-digit'
        });
        return {
            data,
            hora
        };
    }

    window.addEventListener('load', () => {
        criarModal();
        criarBotao();
    });
})();