DEV Community


Quick fix for current spam deluge

Matt Ellen
Ultra-fullstack software developer. Python, JavaScript, C#, C. He/him/his
・1 min read

If you use Grease Monkey or similar, you can use this user script to filter out the current spam posts in your feed:

// ==UserScript==
// @name spam filter
// @version  1
// @include  http*
// @match    *://*
// @grant    none
// @run-at   document-end
// ==/UserScript==

const dev_posts = document.body;

const config = { attributes: false, childList: true, subtree: true };

const callback = function(mutationsList, observer) 

  for(const mutation of mutationsList) 
    if (mutation.type === 'childList') 
      let posts = document.querySelectorAll('article');

      posts.forEach(post =>
        const title = post.querySelector('.crayons-story__title a');
        if(title.innerHTML.replace(/\n/g, '').match(/customer.*care.*number/i))
          console.log('removed post')

// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(dev_posts, config);
Enter fullscreen mode Exit fullscreen mode

Obviously this is a temporary work around while smarter people look at real spam filters, but my feed was unbrowseable :D

You'll need to do a hard refresh for the filter to kick in.

Thanks to MDN for the mutation observer code.

Discussion (2)

mellen profile image
Matt Ellen Author

I've put it into a Gist if people want to offer up improvements.

mellen profile image
Matt Ellen Author

Updated to cover when "customer care number" has things other than spaces in it.