Untitled
unknown
javascript
a year ago
2.3 kB
3
Indexable
Never
// Constants for the threshold and time limits const itemThreshold = 3; // Number of items const timeLimitInSeconds = 1; // Time in seconds // Function to process a single .item element function processItem(item) { const profileElement = item.querySelector('.profile'); if (profileElement) { const profileText = profileElement.textContent.trim(); // Initialize the profileTextCount object for this profile text if (!profileTextCount[profileText]) { profileTextCount[profileText] = { count: 0, lastTimestamp: 0, }; } const currentTime = Date.now(); const lastTimestamp = profileTextCount[profileText].lastTimestamp; // Check if the user has created more than itemThreshold items with the same profile text within the time limit if (profileTextCount[profileText].count >= itemThreshold && currentTime - lastTimestamp <= timeLimitInSeconds * 1000) { // Remove the associated comment const commentSibling = item.nextElementSibling; if (commentSibling && commentSibling.nodeType === Node.COMMENT_NODE) { commentSibling.remove(); } // Remove the item item.remove(); } // Update the count and timestamp for this profile text in the object profileTextCount[profileText].count += 1; profileTextCount[profileText].lastTimestamp = currentTime; } } // Create an object to store the count and timestamp of each profile text const profileTextCount = {}; // Iterate through existing .item elements document.querySelectorAll('#gamelist .item').forEach(item => { processItem(item); }); // Create a MutationObserver to watch for changes in #gamelist const observer = new MutationObserver(mutationsList => { mutationsList.forEach(mutation => { if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { // Iterate through newly added .item elements mutation.addedNodes.forEach(addedNode => { if (addedNode.nodeType === 1 && addedNode.classList.contains('item')) { processItem(addedNode); } }); } }); }); // Start observing #gamelist for changes const gamelist = document.getElementById('gamelist'); observer.observe(gamelist, { childList: true, subtree: true });