Skip to content

Instantly share code, notes, and snippets.

@cahva
Last active February 19, 2025 14:11
Show Gist options
  • Save cahva/32b9d99fd156295aec765aef9bb30263 to your computer and use it in GitHub Desktop.
Save cahva/32b9d99fd156295aec765aef9bb30263 to your computer and use it in GitHub Desktop.
Blacklist domain
<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