Añade un botón para copiar el texto del incidente en mayúsculas
Size
3.5 KB
Version
1.1.2
Created
Dec 24, 2025
Updated
about 1 month ago
1// ==UserScript==
2// @name Copiar Incidente en Mayúsculas
3// @description Añade un botón para copiar el texto del incidente en mayúsculas
4// @version 1.1.2
5// @match https://*.intranet.ejuniper.com/*
6// @icon https://intranet.ejuniper.com/images/favicon.ico
7// ==/UserScript==
8(function() {
9 'use strict';
10
11 function init() {
12 // Buscar el textarea del incidente
13 const incidenteTextarea = document.querySelector('textarea#TemaIncidencia[name="TemaIncidencia"]');
14
15 if (!incidenteTextarea) {
16 console.log('No se encontró el campo de incidente');
17 return;
18 }
19
20 console.log('Campo de incidente encontrado');
21
22 // Crear el botón
23 const copyButton = document.createElement('button');
24 copyButton.textContent = 'Incidencia';
25 copyButton.className = 'ButtonOnPage';
26 copyButton.style.cssText = 'margin-left: 10px; padding: 5px 10px; cursor: pointer; background-color: #007bff; color: white; border: 1px solid #0056b3; border-radius: 3px;';
27
28 // Añadir evento de click
29 copyButton.addEventListener('click', async function(e) {
30 e.preventDefault();
31
32 try {
33 const incidencia = incidenteTextarea.value;
34 const textoMayusculas = document.getElementById('NumeroIncidenteLabel').textContent + ' - ' + textoIncidente.replaceAll('ó','o').replaceAll('á','a').replaceAll('é','e').replaceAll('í','i').replaceAll('ú','u').replaceAll('-','_').toUpperCase();
35
36 var tipo = '';
37 var select = document.getElementById('NuevoTipo');
38 var valorSeleccionado = select.value;
39 var textoSeleccionado = select.options[select.selectedIndex].text;
40
41 switch (true) {
42 case textoSeleccionado.includes('Error'):
43 tipo = 'ERROR';
44 break;
45 case textoSeleccionado.includes('Soporte'):
46 tipo = 'SOPORTE';
47 break;
48 case textoSeleccionado.includes('Desarrollo'):
49 tipo = 'ESTIMACION ANALISIS';
50 break;
51 }
52
53 var textoFinal = incidencia + ' - ' + tipo + ' - ' + textoMayusculas;
54
55 await GM.setClipboard(textoFinal);
56 // Feedback visual
57 const originalText = copyButton.textContent;
58 copyButton.textContent = '✓ Copiado!';
59 copyButton.style.backgroundColor = '#28a745';
60
61 setTimeout(() => {
62 copyButton.textContent = originalText;
63 copyButton.style.backgroundColor = '#007bff';
64 }, 2000);
65 } catch (error) {
66 copyButton.textContent = '✗ Error';
67 copyButton.style.backgroundColor = '#dc3545';
68
69 setTimeout(() => {
70 copyButton.textContent = 'Incidencia';
71 copyButton.style.backgroundColor = '#007bff';
72 }, 2000);
73 }
74 });
75
76 // Insertar el botón después del textarea
77 incidenteTextarea.parentNode.insertBefore(copyButton, incidenteTextarea.nextSibling);
78
79 }
80
81 // Esperar a que el DOM esté listo
82 if (document.readyState === 'loading') {
83 document.addEventListener('DOMContentLoaded', init);
84 } else {
85 init();
86 }
87})();