[GUIDE] Hiding PRSI (and More) From Latest Replies [Desktop Only]

Discussion in 'Site and Forum Feedback' started by AngerDanger, Nov 15, 2018.

  1. AngerDanger, Nov 15, 2018
    Last edited: Nov 28, 2018

    AngerDanger macrumors 68040

    AngerDanger

    Joined:
    Dec 9, 2008
    #1
    Given the influx of threads complaining about the PRSI, ShinyDren's excellent post about hiding the PRSI (and other sub-fora) from the Latest Reply sidebar has received a surprising lack of attention, so I'm reiterating it here.

    The scripts below grabs the list of forums you've ignored when you visit the Forums You Ignore page, and then it hides every reply that falls under corresponding thread-node-numbers from the sidebar.

    You'll need a browser extension that can run user scripts, like TamperMonkey. Paste the following code into a new user script, click save, and view the Forums You Ignore page so it can grab the list. Thanks, @ShinyDren! :)

    Code:
    // ==UserScript==
    // @name         MacRumors - Hide Ignored Forums in Latest Replies in Sidebar
    // @namespace    mr.ShinyDren
    // @version      0.3
    // @description  Hide posts in Latest Replies in sidebar if they are in a node being ignored via site account settings.
    // @author       ShinyDren
    // @match        https://forums.macrumors.com/
    // @match        https://forums.macrumors.com/account/ignored-forums
    // @grant        none
    // ==/UserScript==
    
    // localStorage is assumed
    
    var ignoredNodeRegex = /-47$/i; // fallback value
    var numHidden = 0;
    
    function copyIgnoredToLocalstorage() {
        if ( localStorage.getItem("_mod_sd_siteIgnoreForums") === null ) { // See if the localStorage item exists, display info message if not (only show message once).
            alert("Congratulations, it appears this is the first time running this script on the \"Forums You Ignore\" settings page.\n\nAny forums you select to ignore here will also be used to hide posts in the sidebar on the front page of the forums.");
        }
        var regexList = '';
        var checkedItems = document.querySelectorAll("ul.ignoredNodeList li input:checked"); // Get all matches.
        for (i = 0; i < checkedItems.length; i++) {
            var myValue = checkedItems[i].getAttribute("value");
            if ( i > 0 ) {
                regexList = regexList + "|";
            }
            regexList = regexList + "-" + myValue + "$";
        }
        localStorage.setItem("_mod_sd_siteIgnoreForums", regexList);
    }
    
    function checkReplies() { // Called once at page load.
        var theReplies = document.querySelectorAll(".sidebar .widget .avatarList li"); // Get all matches.
        if ( localStorage.getItem("_mod_sd_siteIgnoreForums") !== null ) { // If the ignoreForums value has been set use it instead of the fallback value.
            ignoredNodeRegex = new RegExp(localStorage.getItem("_mod_sd_siteIgnoreForums"), 'i');
        }
        for (i = 0; i < theReplies.length; i++) {
            if ( ignoredNodeRegex.test(theReplies[i].classList.item(1)) ) { // Contains the text.
                theReplies[i].style.display = "none"; // Hide the reply.
                numHidden++;
            }
        }
        if ( numHidden > 0 ) {
            var myNode = document.createElement("LI");
            var myTextnode = document.createTextNode(numHidden + " replies hidden per your request");
            myNode.appendChild(myTextnode);
            myNode.className = "userTitle"; // match other text
            myNode.style.padding = "10px 0 0 15px"; // adjust spacing
            theReplies[1].parentNode.appendChild(myNode);
        }
    }
    
    var myLoc = location.pathname;
    //alert(myLoc); // for testing
    if ( myLoc == "/account/ignored-forums" ) { // Get ignored items from page
        copyIgnoredToLocalstorage();
    }
    
    if ( myLoc == "/" ) { // Check/Hide replies
        checkReplies();
    }
    EDIT: Below, I've added the ability to also hide your ignored forums from the main list of forums, so right now, I don't even see a PRSI below the Site and Forum Feedback forum. Probably not the most useful addition for most, but I'm also using a stylesheet that makes Xenforo's list of forums look more like VBulletin used to.

    Code:
    // ==UserScript==
    // @name         MacRumors - Hide Ignored Forums AND Their Latest Replies
    // @namespace    mr.ShinyDren
    // @version      0.31
    // @description  Hide posts in Latest Replies in sidebar if they are in a node being ignored via site account settings.
    // @author       ShinyDren & Danger
    // @match        https://forums.macrumors.com/
    // @match        https://forums.macrumors.com/account/ignored-forums
    // @grant        none
    // ==/UserScript==
    
    // localStorage is assumed
    
    var ignoredNodeRegex = /47$/i; // fallback value
    var numHidden = 0;
    
    function copyIgnoredToLocalstorage() {
        if ( localStorage.getItem("_mod_sd_siteIgnoreForums") === null ) { // See if the localStorage item exists, display info message if not (only show message once).
            alert("Congratulations, it appears this is the first time running this script on the \"Forums You Ignore\" settings page.\n\nAny forums you select to ignore here will also be used to hide posts in the sidebar on the front page of the forums.");
        }
        var regexList = '';
        var checkedItems = document.querySelectorAll("ul.ignoredNodeList li input:checked"); // Get all matches.
        for (i = 0; i < checkedItems.length; i++) {
            var myValue = checkedItems[i].getAttribute("value");
            if ( i > 0 ) {
                regexList = regexList + "|";
            }
            regexList = regexList + myValue + "$";
        }
        localStorage.setItem("_mod_sd_siteIgnoreForums", regexList);
    }
    
    function checkReplies() { // Called once at page load.
        var theReplies = document.querySelectorAll(".sidebar .widget .avatarList li"); // Get all matches.
        var theForums = document.querySelectorAll(".level_2");
        if ( localStorage.getItem("_mod_sd_siteIgnoreForums") !== null ) { // If the ignoreForums value has been set use it instead of the fallback value.
            ignoredNodeRegex = new RegExp(localStorage.getItem("_mod_sd_siteIgnoreForums"), 'i');
        }
        for (i = 0; i < theForums.length; i++) {
            //console.log(theReplies[i].classList.item(3));
            if ( ignoredNodeRegex.test(theForums[i].classList.item(3)) ) { // Contains the text.
                theForums[i].style.display = "none"; // Hide the forum.
            }
        }
        for (i = 0; i < theReplies.length; i++) {
            //console.log(theReplies[i].classList.item(3));
            if ( ignoredNodeRegex.test(theReplies[i].classList.item(1)) ) { // Contains the text.
                theReplies[i].style.display = "none"; // Hide the reply.
                numHidden++;
            }
        }
        if ( numHidden > 0 ) {
            var myNode = document.createElement("LI");
            var myTextnode = document.createTextNode(numHidden + " replies hidden per your request");
            myNode.appendChild(myTextnode);
            myNode.className = "userTitle"; // match other text
            myNode.style.padding = "10px 0 0 15px"; // adjust spacing
            theReplies[1].parentNode.appendChild(myNode);
        }
    }
    
    var myLoc = location.pathname;
    //alert(myLoc); // for testing
    if ( myLoc == "/account/ignored-forums" ) { // Get ignored items from page
        copyIgnoredToLocalstorage();
    }
    
    if ( myLoc == "/" ) { // Check/Hide replies
        checkReplies();
    }
    
     
  2. SandboxGeneral Moderator emeritus

    SandboxGeneral

    Joined:
    Sep 8, 2010
    Location:
    Detroit
    #2
    I'm going to give this a try later today. Perhaps now I can completely hide the iPhone forum.
     
  3. SandboxGeneral Moderator emeritus

    SandboxGeneral

    Joined:
    Sep 8, 2010
    Location:
    Detroit
  4. Scepticalscribe Contributor

    Scepticalscribe

    Joined:
    Jul 29, 2008
    Location:
    The Far Horizon
    #4
    What a wonderful idea.
     
  5. AngerDanger thread starter macrumors 68040

    AngerDanger

    Joined:
    Dec 9, 2008
    #5
  6. ShinyDren macrumors member

    ShinyDren

    Joined:
    Jun 25, 2010
    Location:
    Ambitoysterous, USA
    #6
    Nice addition to include it on the main forum list.
     
  7. SandboxGeneral Moderator emeritus

    SandboxGeneral

    Joined:
    Sep 8, 2010
    Location:
    Detroit
    #7
    When I paste the new script into TM, I get a few errors and it won't save.

    A few lines like this:
    Screen Shot 2018-11-17 at 6.38.27 AM.png
     
  8. AngerDanger thread starter macrumors 68040

    AngerDanger

    Joined:
    Dec 9, 2008
    #8
    That's really odd; the part of the script giving an error is the same between both the new and old versions. I always get the same error, but both still run for me. Anyway, I threw a couple of vars before the implicit global variables to narrow their scope and pasted the change into the OP.
     
  9. MacDawg macrumors Core

    MacDawg

    Joined:
    Mar 20, 2004
    Location:
    "Between the Hedges"
    #9
    Thanks for posting this option
    I'm sure many will find it useful and I might give it a whirl myself

    I still use the original Mod posted by @sammich for the Spy using TamperMonkey
    Link to thread with code

    I exclude the PRSI there (along with a few others like the Marketplace, etc)
    It works great for me
     
  10. SandboxGeneral, Nov 17, 2018
    Last edited: Nov 17, 2018

    SandboxGeneral Moderator emeritus

    SandboxGeneral

    Joined:
    Sep 8, 2010
    Location:
    Detroit
    #10
    Odd indeed. This one is on the MBA and still own't work. No errors like earlier, but when I try to save it, it says invalid user script.

    Yesterday I did this on the Mac mini and it worked just fine. Both on Safari with only TM and LastPass installed.

    Edit: Well, I went to the Mac mini and found in TM utilities that I can backup scripts to Google Drive and I did that with my two MacRumors scripts. Then I went back to the MacBook Air and imported the scripts from my Google Drive and now its working.

    Weird. But at least it succeeded.
     
  11. ericgtr12 macrumors 65816

    ericgtr12

    Joined:
    Mar 19, 2015
    #11
    It would be nice if we also had an option to hide ignored users as well. As it stands you can still see their avatar and what they've done both in the sidebar and last post by columns.
     
  12. maflynn Moderator

    maflynn

    Staff Member

    Joined:
    May 3, 2009
    Location:
    Boston
    #12
    There seems to be an error with the second script:
    upload_2018-11-28_14-8-35.png
     
  13. AngerDanger thread starter macrumors 68040

    AngerDanger

    Joined:
    Dec 9, 2008
    #13
    Hahaha, I just realized what you and @SandboxGeneral were getting; I might just be a little bit of an idiot.

    I originally posted the script inside a spoiler tag, so forums.macrumors when through and changed all of the @s into username mentions!

    Alright, fixed. Lemme know if it works.
     
  14. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Sailing beyond the sunset
    #14
    Yes, CODE tags are important.

    Another typical programming expression is [i] which is also the BBCode for "start italic".

    If you're wondering how I got that to appear without starting italics, there's another BBCode for "not BBCode" which is [plain].
     
  15. maflynn Moderator

    maflynn

    Staff Member

    Joined:
    May 3, 2009
    Location:
    Boston
  16. AngerDanger thread starter macrumors 68040

    AngerDanger

    Joined:
    Dec 9, 2008
    #16
    Awesome. Also, would you mind telling me what user script editor you're using? It looks like it runs on iOS, and if so, I'd love to give it a try myself.
     
  17. redheeler macrumors 604

    redheeler

    Joined:
    Oct 17, 2014
    #17
    The alert boxes on MacOS Safari were changed to look more iOS-like a few years ago.
     
  18. maflynn Moderator

    maflynn

    Staff Member

    Joined:
    May 3, 2009
    Location:
    Boston
    #18
    I just used what you recommended - tampermonkey. It was that which gave me the error in my attempt to save the script.
     

Share This Page