// ==UserScript==
// @name MacRumors - No Spoilers in Spy
// @namespace mr.ShinyDren
// @version 0.2.1
// @description Hide snippets of posts on the Spy page if thread title contains the word "Spoiler".
// @author ShinyDren
// @match https://forums.macrumors.com/spy/
// @match https://forums.macrumors.com/spy/
// @grant none
// ==/UserScript==
var checkRegex = /spoiler/i;
function checkTitles() { // Called once at page load.
var threadTitles = document.querySelectorAll(".discussionListItem .info div.whoWhere a"); // Get all matches already loaded.
for (i = 0; i < threadTitles.length; i++) {
if (checkRegex.test(threadTitles[i].innerHTML)) { // Contains the text.
// threadTitles[i].style.color = "orange"; // Change text color.
threadTitles[i].nextSibling.style.display = "none"; // Hide the snippet.
}
}
}
setTimeout(checkTitles, 1000); // Runs once on page load (with 1 second delay) to take care of any existing items (needed if using one of the spy modification scripts by user "sammich" ).
function checkTitle() {
var threadTitle = document.querySelector(".discussionListItem .info div.whoWhere a"); // Items are added one at a time, so it is quicker to only grab the first match.
if (checkRegex.test(threadTitle.innerHTML)) { // Contains the text.
// threadTitle.style.color = "orange"; // Change text color.
threadTitle.nextSibling.style.display = "none"; // Hide the snippet.
}
}
var targetNode = document.querySelector('#spyContents.discussionList ol.discussionListItems'); // Select the node that will be observed for mutations
var config = { childList: true, subtree: true }; // Options for the observer (which mutations to observe)
// Callback function to execute when mutations are observed
var callback = function(mutationsList) {
checkTitle();
};
var observer = new MutationObserver(callback); // Create an observer instance linked to the callback function
observer.observe(targetNode, config); // Start observing the target node for configured mutations