Last active
March 23, 2024 20:22
-
-
Save synthesizerpatel/0ce023d0db4cc6e5c2c5fc3565382264 to your computer and use it in GitHub Desktop.
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 Reddit Post Mute | |
// @namespace Violentmonkey Scripts | |
// @match https://www.reddit.com/* | |
// @grant none | |
// @version 1.0 | |
// @author [email protected] | |
// @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