Skip to content

Instantly share code, notes, and snippets.

@synthesizerpatel
Last active March 23, 2024 20:22
Show Gist options
  • Select an option

  • Save synthesizerpatel/0ce023d0db4cc6e5c2c5fc3565382264 to your computer and use it in GitHub Desktop.

Select an option

Save synthesizerpatel/0ce023d0db4cc6e5c2c5fc3565382264 to your computer and use it in GitHub Desktop.

Revisions

  1. synthesizerpatel revised this gist Mar 23, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions reddit-nuke-by-title-userscript.js
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,8 @@

    // 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');

  2. synthesizerpatel revised this gist Mar 23, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reddit-nuke-by-title-userscript.js
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@
    //node.style.backgroundColor = "red";
    if (title_regex.test(title)) {
    //node.style.backgroundColor = 'yellow';
    node.style.display = "None";
    node.style.display = "none";
    }
    }
    })
  3. synthesizerpatel created this gist Mar 23, 2024.
    50 changes: 50 additions & 0 deletions reddit-nuke-by-title-userscript.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    // ==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.

    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
    });
    })();