Skip to content

Instantly share code, notes, and snippets.

@synthesizerpatel
Last active March 23, 2024 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save synthesizerpatel/0ce023d0db4cc6e5c2c5fc3565382264 to your computer and use it in GitHub Desktop.
Save synthesizerpatel/0ce023d0db4cc6e5c2c5fc3565382264 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Reddit Post Mute
// @namespace Violentmonkey Scripts
// @match https://www.reddit.com/*
// @grant none
// @version 1.0
// @author nar+github@remix.net
// @description 3/12/2024, 5:06:29 PM
// ==/UserScript==
(function () {
// Make reddit posts with any one of these words in the title
// disappear.
//
// Doesn't work in subreddits, only on main page? .. Better than nothing.
title_regex = new RegExp('.*(Bitcoin|Etherium|Crypto).*', 'i');
function handleMutations(mutationsList, observer) {
mutationsList.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() == "article") {
title = node.getAttribute("aria-label");
//node.style.backgroundColor = "red";
if (title_regex.test(title)) {
//node.style.backgroundColor = 'yellow';
node.style.display = "none";
}
}
})
})
};
// Nuke the nodes that existed when the page loaded
const nodesSnapshot = document.evaluate(
"//article",
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
for (let i = 0; i < nodesSnapshot.snapshotLength; i++) {
nodesSnapshot.snapshotItem(i).style.backgroundColor = 'green';
}
observer = new MutationObserver(handleMutations);
main_div = document.querySelector("div > main.main");
observer.observe(main_div, {
childList: true,
subtree: true
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment