Hide a thread?

Discussion in 'Site and Forum Feedback' started by intofx, Aug 8, 2017.

  1. intofx macrumors regular

    Joined:
    Jun 7, 2010
    #1
    Is there a way to enable a option to hide a thread in the forums?

    It's extremely annoying to constantly see these "daily driver" threads for each beta. If threads like this can be hidden by each member with 1 click it will make these forums so much more enjoyable to use on a daily basis.
     
  2. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #2
    No, sorry... there is no way to hide individual threads like that.
     
  3. AngerDanger, Aug 9, 2017
    Last edited: Aug 9, 2017

    AngerDanger macrumors 68030

    AngerDanger

    Joined:
    Dec 9, 2008
    #3
    You could add it in manually with a custom user script.

    Screen Shot 2017-08-09 at 12.55.05 PM.png

    If you have an extension like Tampermonkey installed on your browser, paste this code in as a new script:
    Code:
    // ==UserScript==
    // @name         HideThread
    // @namespace    http://angerdanger.com
    // @version      0.2
    // @description  Hides MR threads with the click of a button.
    // @author       AngerDanger
    // @match        https://forums.macrumors.com/*
    // @grant        none
    // ==/UserScript==
    var blockedTitles;
    
    window.onload = function(){
        var threads = document.getElementsByClassName('discussionListItem');
        if (retrieve_cookie('hiddenThreads'))
            blockedTitles = retrieve_cookie('hiddenThreads').split('*');
        else
            blockedTitles = [];
    
        for (var i = 0; i < threads.length; i++){
            for (var j = 0; j < blockedTitles.length; j++){
                if (threads[i].getElementsByClassName('title')[0].getElementsByClassName('PreviewTooltip')[0].innerHTML == blockedTitles[j]){
                    threads[i].parentElement.removeChild(threads[i]);
                    threads[i] = '';
                    i--;
                    break;
                }
            }
        }
    
        for (var i = 0; i < threads.length; i++){
            var hide = document.createElement('span');
            hide.innerHTML = "X";
            hide.onclick = function (){
                blockedTitles.push(this.parentElement.parentElement.getElementsByClassName('title')[0].childNodes[1].innerHTML);
                create_cookie('hiddenThreads', blockedTitles.join('*'), 30, "/");
                this.parentElement.parentElement.parentElement.removeChild(this.parentElement.parentElement);
            };
            //threads[i].childNodes[1].innerHTML = "X" + threads[i].childNodes[1].innerHTML;
            threads[i].childNodes[1].insertBefore(hide, threads[i].childNodes[1].firstChild);
        }
    };
    
    function create_cookie(name, value, days2expire, path) {
      var date = new Date();
      date.setTime(date.getTime() + (days2expire * 24 * 60 * 60 * 1000));
      var expires = date.toUTCString();
      document.cookie = name + '=' + value + ';' +
                       'expires=' + expires + ';' +
                       'path=' + path + ';';
    }
    
    function retrieve_cookie(name) {
      var cookie_value = "",
        current_cookie = "",
        name_expr = name + "=",
        all_cookies = document.cookie.split(';'),
        n = all_cookies.length;
      for(var i = 0; i < n; i++) {
        current_cookie = all_cookies[i].trim();
        if(current_cookie.indexOf(name_expr) === 0) {
          cookie_value = current_cookie.substring(name_expr.length, current_cookie.length);
          break;
        }
      }
      return cookie_value;
    }
    Pros
    • It's not account specific, so the threads remain blocked once you sign out.
    • Hidden threads can be revealed by disabling the script and enabling again.
    Cons
    • No way to reveal individual threads once hidden.
    • Doesn't work on mobile devices.
    • Only runs after the page is loaded, so you'll to see hidden threads before they poof out of existence.
     
  4. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #4
    I just tried this and maybe I'm doing something wrong. I see the X there by the thread, and when I click that the thread disappears... but when I click "New Posts" again the blocked thread reappears. Am I missing something?
     
  5. AngerDanger macrumors 68030

    AngerDanger

    Joined:
    Dec 9, 2008
    #5
    Huh, I can't reproduce that error. Would you mind telling me which browser you're using?
     
  6. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #6
    On Safari 10.1.2 with Sierra.

    Edit: Must be something with Safari, because I have it working it Chrome.
     
  7. intofx thread starter macrumors regular

    Joined:
    Jun 7, 2010
    #7
    Thank You!!!!! Works great on Safari 11, new post test and all. This functionality should be integrated into all forums by default.
     
  8. AngerDanger macrumors 68030

    AngerDanger

    Joined:
    Dec 9, 2008
    #8
    Hmm, it was developed entirely in Safari. Do you have cookies enabled?
     
  9. Weaselboy, Aug 9, 2017
    Last edited: Aug 9, 2017

    Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #9
    I have "Allow from current website only"... would that block the cookie this needs to save the data?

    Edit: I changed to "Always allow" and still the same.
     
  10. D.T. macrumors 604

    D.T.

    Joined:
    Sep 15, 2011
    Location:
    Vilano Beach, FL
    #10
    FWIW, works in Chrome (though the cursor is an i-beam when you rollover the X).

    Fun!
     
  11. AngerDanger, Aug 9, 2017
    Last edited: Aug 9, 2017

    AngerDanger macrumors 68030

    AngerDanger

    Joined:
    Dec 9, 2008
    #11
    Glad to hear it works! It's easy enough to bodge this shoddy version of thread blocking together, but forum software like XenForo is so advanced and abstract that implementing the same feature would probably take forever.
    Erm… possibly? I'm not entirely sure what's up but will look into it.

    EDIT
    I just realized that I, a lowly macrumors 68030, D.T. and intofx are not moderators; it could be that the page you're served up has the titles of threads appended later in the node tree to each than the pages we see.

    Would you mind attaching a screenshot similar to the one in my OP?
    Yeah… I'm not exactly the most proficient programmer; graphics are more my thing. ;)
     
  12. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #12
    Sorry, I can't show a screenshot as that would expose certain tools we have. But I bet you are correct that is the issue. When logged in as a moderator things are quite a bit different. I appreciate the effort. :)
     
  13. AngerDanger macrumors 68030

    AngerDanger

    Joined:
    Dec 9, 2008
    #13
    Ah, it's probably one of those tools that causes the incompatibility. I might be able to create a version that's less naïve and will let you know (if you'd like) when it's finished.
     
  14. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #14
    Please do. Thanks
     
  15. AngerDanger macrumors 68030

    AngerDanger

    Joined:
    Dec 9, 2008
    #15
    @Weaselboy, I've updated my OP with code that might work for moderators as well. It also blocks individual Wiki posts now.
     
  16. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #16
    Thanks for trying... but no joy. :(
     

Share This Page