(function () {
let wordCollect = true; // @todo NEEDS TO BE CHANGED MANUALLY :X
let captchaOk = false;
let wordCollectInput = document.getElementById('jw-word-collect');
let inputEmpty = true;
let noViolation = false;
let wordSelected = false;
let ageOk = false;
let consentOk = false;
let submitButton = document.getElementById('submitButton');
const forbiddenSuggestions = ["stolzmonat", "hurensohn", "döp", "döpdödödöp", "döp döp döp", "döp dödö döp", "döp dö dö döp", "döp döö döö döp", "döpp", "neger", "nigger", "remigration", "deutschland den deutschen", "ausländer raus"];
let form = document.getElementById('form');
let debug = false;
function checkCanSubmit() {
if (debug) {
submitButton.disabled = false;
return true;
}
let canSubmit = noViolation && ageOk && captchaOk && (wordSelected || !inputEmpty) && consentOk;
submitButton.disabled = !canSubmit;
return canSubmit;
}
let ageSelect = document.getElementById('age');
let checkAgeSelected = function () {
let ageValue = parseInt(ageSelect.value);
ageOk = ageValue > -1;
checkCanSubmit();
}
ageSelect.addEventListener('change', checkAgeSelected);
checkAgeSelected();
let wordElements = document.querySelectorAll('div.word');
for (let i = 0; i < wordElements.length; i++) {
let el = wordElements[i];
el.addEventListener('click', function () {
this.querySelector('input').click();
});
}
let consentElement = document.querySelector('div.consent');
consentElement.addEventListener('click', function (e) {
if ('checkbox' !== e.target.type && e.target.nodeName.toUpperCase() !== 'A') {
this.querySelector('input').click();
}
});
let inputElements = document.querySelectorAll('input[type=radio]');
let checkWordSelected = function () {
wordSelected = false;
for (let i = 0; i < inputElements.length; i++) {
wordSelected = wordSelected || inputElements[i].checked;
}
checkCanSubmit();
};
for (let i = 0; i < inputElements.length; i++) {
inputElements[i].addEventListener('click', checkWordSelected);
}
checkWordSelected();
let checkInputNotEmpty = function () {
const input = wordCollectInput.value.trim().toLowerCase();
inputEmpty = input.length === 0;
noViolation = forbiddenSuggestions.reduce((acc, cur) => {
return acc && !input.includes(cur);
}, true);
debugger;
// noViolition = !forbiddenSuggestions.includes(input);
checkCanSubmit();
};
if (wordCollect) {
wordCollectInput.addEventListener('keyup', checkInputNotEmpty);
checkInputNotEmpty();
}
let consentCheckboxElement = document.querySelector('div.consent input[type=checkbox]');
let checkConsent = function () {
consentOk = consentCheckboxElement.checked;
checkCanSubmit();
};
consentCheckboxElement.addEventListener('change', checkConsent);
checkConsent();
window.onRecaptchaCallback = function () {
captchaOk = true;
checkCanSubmit();
}
window.onRecaptchaExpiredCallback = function () {
captchaOk = false;
checkCanSubmit();
}
let onFormSubmit = function (e) {
if (debug) return true;
let response = window.grecaptcha.getResponse();
if (response.length === 0) {
alert("Bitte zeige uns, dass du kein Roboter bist...");
e.preventDefault();
return false;
}
if (!checkCanSubmit()) {
alert("Bitte überprüfe deine Eingaben...");
e.preventDefault();
return false;
}
}
submitButton.addEventListener('click', function () {
form.submit();
});
form.addEventListener('submit', onFormSubmit);
checkCanSubmit();
})();