Last active
February 19, 2025 14:11
-
-
Save cahva/32b9d99fd156295aec765aef9bb30263 to your computer and use it in GitHub Desktop.
Blacklist domain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const restrictedDomains = [ | |
'@example.com', | |
'@foo.bar' | |
]; | |
async function initEmailCheck() { | |
try { | |
const emailInput = await waitForElementPromise('#EMAIL_2'); | |
const submitButton = await waitForElementPromise('#submit-button'); | |
submitButton.addEventListener('click', function (event) { | |
const email = emailInput.value.toLowerCase(); | |
const isRestricted = restrictedDomains.some(domain => | |
email.includes(domain.toLowerCase()) | |
); | |
let errorMsg = document.getElementById('email-error-message'); | |
if (isRestricted) { | |
event.preventDefault(); // Prevent form submission | |
emailInput.style.borderColor = 'red'; | |
if (!errorMsg) { | |
errorMsg = document.createElement('div'); | |
errorMsg.id = 'email-error-message'; | |
errorMsg.style.color = 'red'; | |
errorMsg.style.fontSize = '12px'; | |
errorMsg.textContent = 'Something went wrong.'; | |
emailInput.parentNode.appendChild(errorMsg); | |
} | |
} else { | |
emailInput.style.borderColor = ''; | |
if (errorMsg) { | |
errorMsg.remove(); | |
} | |
} | |
}); | |
} catch (error) { | |
console.error('Error initializing email check:', error); | |
} | |
} | |
if (window.location.href.includes('/register')) { | |
initEmailCheck(); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment