Aggiunti file javascript
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
// ==UserScript==
|
||||
// @name Robot WORKING Portale - FIX CONNESSIONE
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @description Inserimento, Estrazione Tabella e invio a PHP per Firebird
|
||||
// @version 3.3
|
||||
// @match *://www.ilportaledellautomobilista.it/immatricolazioni/*
|
||||
// @grant GM_xmlhttpRequest
|
||||
// @connect 192.168.1.33
|
||||
// ==/UserScript==
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const ENDPOINT_GET = "http://192.168.1.33/hook/dati4.php";
|
||||
const ENDPOINT_POST = "http://192.168.1.33/hook/ans4.php";
|
||||
const TARGET_HOME = "https://www.ilportaledellautomobilista.it/immatricolazioni/certificatoConformitaDatiTecniciVE/Read_initAction.action?pageStatus=SEARCH";
|
||||
|
||||
let completatoLocalmente = false;
|
||||
|
||||
console.log("[TM] Inizio monitoraggio...");
|
||||
|
||||
const clean = (val) => (val === "." || !val) ? "" : val.toString().trim();
|
||||
|
||||
function fetchDati() {
|
||||
if (completatoLocalmente) return;
|
||||
|
||||
GM_xmlhttpRequest({
|
||||
method: "GET",
|
||||
url: ENDPOINT_GET,
|
||||
nocache: true,
|
||||
onload: function(response) {
|
||||
try {
|
||||
const data = JSON.parse(response.responseText);
|
||||
|
||||
if (data.tipo === 'DATI_COC' && data.task === 'fare') {
|
||||
// CONTROLLO FONDAMENTALE: C'è la tabella risultati?
|
||||
const tabella = document.getElementById('listTable');
|
||||
|
||||
if (tabella) {
|
||||
// Se c'è la tabella, estraiamo e chiudiamo il task sul DB
|
||||
completatoLocalmente = true;
|
||||
estraiESalva(data.valore1);
|
||||
}
|
||||
else if (window.location.href.includes("pageStatus=SEARCH") || window.location.href.endsWith("Read_initAction.action")) {
|
||||
// Se siamo nel form e NON c'è ancora la tabella, compiliamo e clicchiamo
|
||||
inserisciDati(data);
|
||||
}
|
||||
}
|
||||
} catch (e) { console.error("Errore JSON", e); }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function inserisciDati(d) {
|
||||
// Evitiamo click multipli se abbiamo già cliccato in questa sessione
|
||||
if (window.alreadyClicked) return;
|
||||
|
||||
console.log("[TM] Compilazione form...");
|
||||
const mappa = {
|
||||
"VEFrom.descrizioneFamigliaVeicolo": d.valore1,
|
||||
"VEFrom.descrizioneVarianteVeicolo": d.valore2,
|
||||
"VE.codiceOmologazioneEuropea": d.valore3,
|
||||
"VE.codiceMarchioVeicolo": d.valore4,
|
||||
"progressivoCostruttoreVeicolo": d.valore5
|
||||
};
|
||||
|
||||
let trovato = false;
|
||||
Object.keys(mappa).forEach(key => {
|
||||
let input = document.querySelector(`input[name*="${key}"]`);
|
||||
if (input) {
|
||||
input.value = clean(mappa[key]);
|
||||
trovato = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (trovato) {
|
||||
const btn = document.getElementById('RicercaCertificatoConformitaDatiTecniciVE_button_value_searchElement');
|
||||
if (btn) {
|
||||
console.log("[TM] Click Ricerca!");
|
||||
window.alreadyClicked = true;
|
||||
btn.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function estraiESalva(v1) {
|
||||
console.log("[TM] Tabella trovata. Invio dati al DB...");
|
||||
const rows = document.querySelectorAll('#listTable tbody tr');
|
||||
let risultati = [];
|
||||
|
||||
rows.forEach(row => {
|
||||
const celle = Array.from(row.querySelectorAll('td'))
|
||||
.filter(td => !td.querySelector('input[type="radio"]'))
|
||||
.map(td => td.innerText.trim());
|
||||
if (celle.length > 0) risultati.push(celle);
|
||||
});
|
||||
|
||||
GM_xmlhttpRequest({
|
||||
method: "POST",
|
||||
url: ENDPOINT_POST,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
data: JSON.stringify({
|
||||
tipo: "SALVATAGGIO_DB",
|
||||
task: "COMPLETATO",
|
||||
riferimento: v1,
|
||||
tabella_dati: risultati
|
||||
}),
|
||||
onload: function() {
|
||||
console.log("[TM] Task inviato al server. Torno alla Home.");
|
||||
// Aspettiamo 2 secondi per sicurezza prima di tornare alla home
|
||||
setTimeout(() => { window.location.href = TARGET_HOME; }, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(fetchDati, 3000);
|
||||
})();
|
||||
Reference in New Issue
Block a user