if (!window.__decoautoLoaded) { window.__decoautoLoaded = true; (function($){ // --- Temps de déconnexion --- var tpsDeconnexionSpip = parseInt("#SESSION{tps_deconnexion}", 10) * 1000 || 0; if (tpsDeconnexionSpip <= 0) return; // --- Déconnexion --- function deconnecte_session() { var url_logout_spip = "[(#CONFIG{decoauto/url_deconnexion}|oui)#URL_LOGOUT{#CONFIG{decoauto/url_deconnexion}|decoauto_generer_url}][(#CONFIG{decoauto/url_deconnexion}|non)#URL_LOGOUT]"; var url_logout_propre = url_logout_spip.replace(/&/g, "&"); window.location.href = url_logout_propre; } var compteurDeconnexion = setTimeout(deconnecte_session, tpsDeconnexionSpip); var timerSec = tpsDeconnexionSpip / 1000; var flash = false; // --- Barre + countdown --- if ($('#decoauto-bar').length === 0) { $('body').append(`
`); } var $bar = $('#decoauto-bar'); var $countdown = $('#decoauto-countdown'); // --- Mise à jour visuelle --- function updateCountdown() { if (timerSec <= 0) { $countdown.text('00:00'); $bar.css('width','0%').css('background','#ff0000'); return; } var minutes = Math.floor(timerSec / 60); var seconds = timerSec % 60; var mStr = minutes < 10 ? '0'+minutes : minutes; var sStr = seconds < 10 ? '0'+seconds : seconds; $countdown.text(`${mStr}:${sStr}`); var pct = (timerSec / (tpsDeconnexionSpip / 1000)) * 100; $bar.css('width', pct + '%'); // Couleurs progressives if (pct > 50) $bar.css('background','#76c7c0'); // vert else if (pct > 20) $bar.css('background','#ffa500'); // orange else $bar.css('background', flash ? '#ff0000' : '#ff6666'); // rouge clignotant // Clignotement seulement dans la dernière minute if (timerSec <= 60) flash = !flash; } // --- Décrémentation --- setInterval(function() { timerSec--; updateCountdown(); }, 1000); // --- Reset du timer sur activité --- function resetTimer() { clearTimeout(compteurDeconnexion); compteurDeconnexion = setTimeout(deconnecte_session, tpsDeconnexionSpip); timerSec = tpsDeconnexionSpip / 1000; flash = false; updateCountdown(); } $(document).on('keydown click mousemove', resetTimer); updateCountdown(); })(jQuery); }