86 lines
3.0 KiB
JavaScript
86 lines
3.0 KiB
JavaScript
// ==UserScript==
|
|
// @name Portaledeltrasporto WORKING - Full Automation (SPA Fix)
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 2.5
|
|
// @description Automazione completa dalla ricerca al tasto Procedi, ottimizzata per React/SPA.
|
|
// @author Tu
|
|
// @match *://www.ilportaledeltrasporto.it/nove/gestioneistanzanove/spa/*
|
|
// @grant none
|
|
// @run-at document-end
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const TELAIO = 'VR3UPHNE7R5039330';
|
|
|
|
// Funzione universale per cliccare in modo che React se ne accorga
|
|
function clickReactSafe(element) {
|
|
if (!element) return;
|
|
console.log('[TM] Clicco elemento:', element.textContent.trim() || 'Bottone Azione');
|
|
|
|
const opts = { bubbles: true, cancelable: true, view: window };
|
|
element.dispatchEvent(new MouseEvent('mousedown', opts));
|
|
element.dispatchEvent(new MouseEvent('mouseup', opts));
|
|
element.click();
|
|
}
|
|
|
|
function setInputReactSafe(input, value) {
|
|
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
|
|
input.focus();
|
|
setter.call(input, value);
|
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
input.blur();
|
|
}
|
|
|
|
// LOGICA PRINCIPALE
|
|
function eseguiAutomazione() {
|
|
const url = window.location.href;
|
|
|
|
// --- FASE 1: RICERCA ---
|
|
if (url.includes('le-mie-istanze')) {
|
|
const input = document.getElementById('numeroTelaio');
|
|
const btnCerca = Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('Cerca'));
|
|
const btnTabella = document.querySelector('button.action-button-table');
|
|
|
|
// Se c'è l'input e non è ancora stato scritto il telaio
|
|
if (input && input.value !== TELAIO) {
|
|
setInputReactSafe(input, TELAIO);
|
|
console.log('[TM] Telaio inserito');
|
|
setTimeout(() => { if(btnCerca) clickReactSafe(btnCerca); }, 500);
|
|
}
|
|
|
|
// Se appare il bottone nella tabella, cliccalo
|
|
if (btnTabella) {
|
|
clickReactSafe(btnTabella);
|
|
}
|
|
}
|
|
|
|
// --- FASE 2: PROCEDI ---
|
|
if (url.includes('/abilitazione/')) {
|
|
const btnProcedi = Array.from(document.querySelectorAll('button'))
|
|
.find(b => b.textContent.trim() === 'Procedi');
|
|
|
|
if (btnProcedi && !btnProcedi.disabled) {
|
|
clickReactSafe(btnProcedi);
|
|
}
|
|
}
|
|
}
|
|
|
|
// IL SEGRETO PER LE SPA: Osserva i cambiamenti del DOM
|
|
// Invece di refreshare, lo script si accorge se appaiono nuovi pezzi di pagina
|
|
const observer = new MutationObserver(() => {
|
|
eseguiAutomazione();
|
|
});
|
|
|
|
observer.observe(document.body, {
|
|
childList: true,
|
|
subtree: true
|
|
});
|
|
|
|
// Primo avvio
|
|
setTimeout(eseguiAutomazione, 1000);
|
|
|
|
console.log('[TM] Monitoraggio SPA attivo...');
|
|
})(); |