// ==UserScript== // @name HideSpoiler // @description Hide spoiler pictures on /r/MMA // @include https://www.reddit.com/r/MMA/ // @version 1 // @grant none // ==/UserScript== var forEachSelectorNode = function (node, query, cb) { var nodes = node.querySelectorAll(query); if (nodes) { for (var n of nodes) { if (false === cb(n)) { break; } } } } var forEachSelector = function (query, cb) { return forEachSelectorNode(document, query, cb); } var re_title = /[\[\(]\s*spoiler\s*[\]\)]/i; forEachSelector("div[class~='entry']", function (div) { var a = forEachSelectorNode(div, "p[class~='title'] a[class~='title']", function (a) { if (a.text.match(re_title)) { var href = a.getAttribute("href"); var thumb_node_a = a.parentNode.parentNode.previousElementSibling; thumb_node_a.setAttribute("href", href); thumb_node_a.classList.add("self"); forEachSelectorNode(thumb_node_a, "img", function (img) { img.parentNode.removeChild(img); return false; }); } }); });