let form = document.querySelector('.showwaiter'); if(form != null) { checkProduct(form, { product: 'product' }); form.addEventListener('submit', event => { event.preventDefault(); if (form.containsProduct()) return; form.submit(); }); } function checkProduct(form, { product = 'product', checkTime = 2000 } = {}) { const startTime = Date.now(); let hasInteraction = false; function checkForInteraction() { hasInteraction = true; } const events = ['keydown', 'mousemove', 'touchstart', 'click']; events.forEach(event => { document.addEventListener(event, checkForInteraction, { once: true }); }); form.containsProduct = function () { const fillTime = Date.now() - startTime; const zoHee = fillTime < checkTime; const productInput = form.querySelector(`[name=\"${product}\"]`); const hasProductValue = productInput?.value?.trim(); const niksGedaan = !hasInteraction; return zoHee || !!hasProductValue || niksGedaan; }; }