Last active
February 5, 2024 13:53
-
-
Save rozsazoltan/f7bf57263e0d9e5ac9a944c6501ed754 to your computer and use it in GitHub Desktop.
GitHub Gist Discover Guard: Spam Filter
This file contains 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
// Function to remove gist elements with Arabic, Thai, or Russian characters | |
const removeSpams = () => { | |
// Object containing character sets for Arabic, Thai, and Russian | |
const charSets = { | |
arabic: '[\\u0600-\\u06FF]', | |
thai: '[\\u0E00-\\u0E7F]', | |
russian: '[\\u0400-\\u04FF]' | |
}; | |
// Constructing a single regex for all character sets | |
const spamRegex = new RegExp(Object.values(charSets).join('|')); | |
// Select and iterate through all gist elements | |
document.querySelectorAll('.gist-snippet').forEach((snippet) => { | |
const content = snippet.textContent; | |
// Check if the content contains Arabic, Thai, or Russian characters | |
if (spamRegex.test(content)) { | |
// Hide the entire gist element | |
snippet.style.display = 'none'; | |
} | |
}); | |
}; | |
// Run the removeSpams function on page load | |
removeSpams(); | |
// Event listener for pagination buttons | |
document.addEventListener('click', async (event) => { | |
// Check if the click occurred on a pagination button | |
const isPaginationButton = event.target.matches('a') && event.target.parentElement.matches('div.pagination'); | |
if (isPaginationButton) { | |
// Wait for the new page to load (1 second delay) | |
await new Promise((resolve) => setTimeout(resolve, 1000)); | |
// Run the removeSpams function after pagination | |
removeSpams(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment