Last active
December 4, 2020 03:02
-
-
Save Mellen/6e0c9398fe42d803c76bd2ec6ffc080b to your computer and use it in GitHub Desktop.
Filters out the posts from the dev.to feed that are obviously spam
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
// ==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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment