DEV Community

loading...

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     dev.to spam filter
// @version  1
// @include  http*
// @match    *://dev.to/*
// @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))
        {
          post.parentElement.removeChild(post);
          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)

Collapse
mellen profile image
Matt Ellen Author

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

Collapse
mellen profile image
Matt Ellen Author

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