Deaktiviert Submit-Button für 5 Sekunden und bis User interagiert

This commit is contained in:
Andreas Hnida 2024-02-27 10:37:56 +00:00
commit e2affa38fc

View file

@ -1,6 +1,7 @@
window.onload = function () {
const FORMDEBUG = false;
const btn = document.getElementById('bestellformular-btn');
// initieiere Zeitmessung zur Botprevention
var startTime = Date.now();
@ -9,9 +10,17 @@ window.onload = function () {
var userInteracted = false;
function setUserInteracted() {
var timeSpent = (Date.now() - startTime) / 1000; // Zeit in Sekunden
if (timeSpent > 5) {
btn.disabled = false;
}
userInteracted = true;
}
setTimeout(function () {
if (userInteracted) {
btn.disabled = false;
}
}, 5000);
// Eventlistener für Interaktionen - setzt userInteracted auf true bei Interaktion
document.addEventListener("mousedown", setUserInteracted);
document.addEventListener("touchstart", setUserInteracted);
@ -23,7 +32,6 @@ window.onload = function () {
const form = e.target;
const notification = document.getElementById('notification');
const btn = document.getElementById('bestellformular-btn');
const zsrTooltip = document.getElementById('zsr-tooltip');
// Spinner und button disabled anzeigen