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