Hey, someone else is getting spammed these days. Here’s a quick bandage script that should prevent some spams.
// Array of keywords to block
const blockedKeywords = [
// Keywords related to spam services
'speedyindexbot', 'service for indexing', '200 links for free',
// Keywords related to drugs
'Купить', 'Кокаин', 'Доставка', 'Киев', 'Закладки', 'Чистый', 'САЙТ',
'Erectile dysfunction', 'TruePills', 'Viagra', 'Sildenafil', 'Cialis', 'Levitra',
// Keywords related to gambling
'free casino games', 'no download', 'no registration', 'real money', 'casino',
'blackjack', 'gambling', 'slots',
// Keywords related to unsolicited promotions
'social ads visits', 'cyber-monkey', 'onion',
// Keywords related to heating and fireplaces (specific spam)
'Печи', 'камины', 'Москва', 'интернет магазин', 'отопления',
// Common spam keywords
'free', 'win', 'winner', 'claim', 'urgent', 'discount', 'deal', 'prize', 'credit',
'loan', 'debt', 'insurance', 'money', 'cash', 'payout', 'cheap', 'buy', 'purchase',
'order now', 'limited time', 'offer', 'sale', 'exclusive', 'click here', 'subscribe',
'unsubscribe', 'newsletter', 'pills', 'medication', 'pharmacy', 'investment', 'profit',
'earn', 'income', 'work from home', 'weight loss',
// Keywords related to adult content
'sex', 'porn', 'adult', 'xxx', 'nude', 'naked', 'hentai', 'escort', 'prostitution',
// Keywords related to drugs
'drug', 'cocaine', 'heroin', 'meth', 'weed', 'cannabis', 'marijuana', 'lsd',
// Keywords related to cryptocurrencies
'crypto', 'bitcoin', 'ethereum', 'blockchain', 'nft', 'ico', 'token'
];
const form = document.querySelectorAll('form');
for (let index = 0; index < form.length; index++) {
const formEl = form[index];
const messageInput = formEl.querySelectorAll('textarea');
const submitBtn = formEl.querySelector('input[type="submit"]')
// Create the error message div
const errorMessage = document.createElement('div');
errorMessage.className = 'error-message';
errorMessage.style.display = 'none';
errorMessage.style.color = 'red';
formEl.insertBefore(errorMessage, submitBtn);
/**
* Check if the message contains any blocked keywords.
* @param {string} message - The message to check.
* @return {string|undefined} - The first blocked keyword found or undefined.
*/
function checkForBlockedKeywords(message) {
return blockedKeywords.find(keyword => message.includes(keyword.toLowerCase()));
}
/**
* Toggle the error message display and submit button state.
* @param {boolean} containsBlockedKeyword - Whether the message contains a blocked keyword.
* @param {string} [blockedKeyword=''] - The blocked keyword found.
*/
function toggleErrorDisplay(containsBlockedKeyword, blockedKeyword = '') {
if (containsBlockedKeyword) {
submitBtn.disabled = true;
submitBtn.classList.add('disabled');
submitBtn.style.opacity = '0.5';
errorMessage.style.display = 'block';
errorMessage.textContent = `The message contains a blocked keyword: ${blockedKeyword}`;
} else {
submitBtn.disabled = false;
submitBtn.classList.remove('disabled');
submitBtn.style.opacity = '1';
errorMessage.style.display = 'none';
}
}
// Add input event listener to each textarea
for (let i = 0; i < messageInput.length; i++) {
const element = messageInput[i];
element.addEventListener('input', function() {
const message = element.value.toLowerCase();
const blockedKeyword = checkForBlockedKeywords(message);
toggleErrorDisplay(!!blockedKeyword, blockedKeyword);
});
}
// Add submit event listener to the form
formEl.addEventListener('submit', function(event) {
let blockedKeyword = false;
for (let i = 0; i < messageInput.length; i++) {
const element = messageInput[i];
const message = element.value.toLowerCase();
blockedKeyword = checkForBlockedKeywords(message);
}
if (blockedKeyword) {
event.preventDefault();
alert(`The message contains a blocked keyword: ${blockedKeyword}`);
}
});
}