Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

intofx

macrumors regular
Original poster
Jun 7, 2010
184
306
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.
 
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.
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.
 
Last edited:
  • Like
Reactions: intofx
You could add it in manually with a custom user script.
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?
 
  • Like
Reactions: AngerDanger
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?
Huh, I can't reproduce that error. Would you mind telling me which browser you're using?
 
Hmm, it was developed entirely in Safari. Do you have cookies enabled?
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.
 
Last edited:
Thank You!!!!! Works great on Safari 11, new post test and all. This functionality should be integrated into all forums by default.
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.
I have "Allow from current website only"... would that block the cookie this needs to save the data?
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?
FWIW, works in Chrome (though the cursor is an i-beam when you rollover the X).

Fun!
Yeah… I'm not exactly the most proficient programmer; graphics are more my thing. ;)
 
Last edited:
  • Like
Reactions: Weaselboy
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.
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. :)
 
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. :)
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.
 
  • Like
Reactions: Weaselboy
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.