54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
// ==UserScript==
|
|
// @name Click "Gestisci le istanze"
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 3.0
|
|
// @description Cerca e preme il pulsante con testo specifico
|
|
// @author YourName
|
|
// @match https://www.ilportaledeltrasporto.it/nove/gestioneistanzanove/spa*
|
|
// @grant none
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
// Funzione per cercare e cliccare
|
|
function findAndClick() {
|
|
// Recupera tutti i pulsanti nella pagina
|
|
const buttons = Array.from(document.querySelectorAll('button'));
|
|
|
|
// Cerca il pulsante che contiene il testo desiderato (case-sensitive)
|
|
const targetButton = buttons.find(btn =>
|
|
btn.textContent.trim().includes("Gestisci le istanze")
|
|
);
|
|
|
|
if (targetButton) {
|
|
console.log("Pulsante 'Gestisci le istanze' trovato! Clicco...");
|
|
|
|
// Focus e click per massima compatibilità
|
|
targetButton.focus();
|
|
targetButton.click();
|
|
|
|
// Restituisce true se ha trovato il pulsante
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Usiamo un MutationObserver: è più efficiente del timer perché
|
|
// "osserva" i cambiamenti del sito e interviene appena appare il tasto
|
|
const observer = new MutationObserver((mutations, obs) => {
|
|
if (findAndClick()) {
|
|
obs.disconnect(); // Una volta cliccato, smette di osservare
|
|
}
|
|
});
|
|
|
|
// Inizia a osservare i cambiamenti nel body della pagina
|
|
observer.observe(document.body, {
|
|
childList: true,
|
|
subtree: true
|
|
});
|
|
|
|
// Eseguiamo anche un controllo immediato al caricamento
|
|
window.addEventListener('load', findAndClick);
|
|
|
|
})(); |