118 lines
4.7 KiB
JavaScript
118 lines
4.7 KiB
JavaScript
// ==UserScript==
|
|
// @name EUCARIS php Bridge - VERSIONE ANTI-LOOP
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 7.1
|
|
// @description Navigazione forzata con blocco dei ricarichi infiniti
|
|
// @author GATTO + Gemini
|
|
// @match *://www.ilportaledellautomobilista.it/Info/*
|
|
// @grant GM_xmlhttpRequest
|
|
// @grant GM_setValue
|
|
// @grant GM_getValue
|
|
// @connect 192.168.1.33
|
|
// @run-at document-end
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const PHP_URL = "http://192.168.1.33/hook/dati1.php";
|
|
const URL_STEP_1 = "/Info/info/CreateGraph_home.action?SESSION_INFO_NODO_CORRENTE=N370&CRITERIO=99&METODO=/criteria-page/home.jsp";
|
|
const URL_STEP_2 = "/Info/info/CreateGraph_getFunzioneSelezionata.action?SESSION_INFO_NODO_CORRENTE=N371";
|
|
const URL_HOME = "/Info/info/CreateGraph_home.action?SESSION_INFO_NODO_CORRENTE=N21&CRITERIO=99&METODO=/criteria-page/home.js";
|
|
|
|
let isRedirecting = false;
|
|
|
|
// --- FUNZIONE DI SALTO SICURA (EVITA LOOP) ---
|
|
function safeRedirect(targetPath) {
|
|
const fullTarget = window.location.origin + targetPath;
|
|
if (window.location.href !== fullTarget) {
|
|
console.log("Reindirizzamento a: " + targetPath);
|
|
isRedirecting = true;
|
|
window.location.href = fullTarget;
|
|
} else {
|
|
console.log("Già a destinazione, evito il loop.");
|
|
}
|
|
}
|
|
|
|
function autofillEucaris() {
|
|
const telaioDaInserire = GM_getValue("ultimo_telaio", null);
|
|
|
|
if (window.location.href.includes("N371") && telaioDaInserire) {
|
|
const radio = document.getElementById("CreateGraph_getFunzioneSelezionata_criterio77");
|
|
const inputTelaio = document.getElementById("CreateGraph_getFunzioneSelezionata_criteri_77__telaio");
|
|
const inputStato = document.getElementById("CreateGraph_getFunzioneSelezionata_criteri_77__idStato");
|
|
const btnConfirm = document.getElementById("CreateGraph_getFunzioneSelezionata_button_value_confirm");
|
|
|
|
if (radio) radio.checked = true;
|
|
if (inputTelaio) inputTelaio.value = telaioDaInserire;
|
|
if (inputStato) inputStato.value = "MCI";
|
|
|
|
if (inputTelaio && inputTelaio.value !== "") {
|
|
GM_setValue("ultimo_telaio", null);
|
|
if (btnConfirm) {
|
|
setTimeout(() => { btnConfirm.click(); }, 800);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function checkTask() {
|
|
if (isRedirecting) return;
|
|
|
|
GM_xmlhttpRequest({
|
|
method: "GET",
|
|
url: PHP_URL + "?nocache=" + new Date().getTime(),
|
|
onload: function(response) {
|
|
try {
|
|
const data = JSON.parse(response.responseText);
|
|
if (data.task && data.task.toLowerCase() === "fare") {
|
|
if (data.valore1 && data.tipo.toUpperCase() === "EUCARIS") {
|
|
GM_setValue("ultimo_telaio", data.valore1);
|
|
}
|
|
eseguiSalto(data);
|
|
}
|
|
} catch (e) { }
|
|
}
|
|
});
|
|
}
|
|
|
|
function eseguiSalto(data) {
|
|
const tipo = data.tipo.toUpperCase();
|
|
const currentUrl = window.location.href;
|
|
|
|
if (tipo === "EUCARIS") {
|
|
// Se non sono ancora in N370 o N371, vai a Step 1
|
|
if (!currentUrl.includes("N370") && !currentUrl.includes("N371")) {
|
|
safeRedirect(URL_STEP_1);
|
|
}
|
|
// Se sono in N370, segnalo completato e vado a Step 2
|
|
else if (currentUrl.includes("N370")) {
|
|
isRedirecting = true;
|
|
const update = { ...data, task: "completato" };
|
|
GM_xmlhttpRequest({
|
|
method: "POST",
|
|
url: PHP_URL,
|
|
data: JSON.stringify(update),
|
|
headers: { "Content-Type": "application/json" },
|
|
onload: () => { safeRedirect(URL_STEP_2); }
|
|
});
|
|
}
|
|
}
|
|
else if (tipo === "RESET") {
|
|
if (!currentUrl.includes("N21")) { // Salta a home solo se non ci sei già
|
|
isRedirecting = true;
|
|
const update = { ...data, task: "completato" };
|
|
GM_xmlhttpRequest({
|
|
method: "POST",
|
|
url: PHP_URL,
|
|
data: JSON.stringify(update),
|
|
headers: { "Content-Type": "application/json" },
|
|
onload: () => { safeRedirect(URL_HOME); }
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
autofillEucaris();
|
|
setInterval(checkTask, 3000); // Leggermente più lento per dare tempo alla pagina di stabilizzarsi
|
|
})(); |