Greasy Fork is available in English.

Remove related answers on Quora

Removes related answers

// ==UserScript==
// @name         Remove related answers on Quora
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Removes related answers
// @author       https://greasyfork.org/zh-CN/users/36570-bianwenbo
// @match        https://www.quora.com/*
// @match        https://quora.com/*
// @icon         https://www.google.com/s2/favicons?domain=quora.com
// @grant        none
// ==/UserScript==
/* jshint esversion: 6 */

(function() {
    'use strict';
    var logRemovalsToDevConsole = false; // Change this to true to log removals to the console

    setInterval(function() {
        // search for the "Promoted by" or "Sponsored by" or "Ad by" or "Related Answer" string in a block with a small font
        var xpathResult = document.evaluate("//div[contains(@class, '--small') and (contains(., 'Promoted by') or contains(., 'Sponsored by') or contains(., 'Ad by') or contains(., 'Related Answer'))]", document, null, XPathResult.ANY_TYPE, null);
        if (!xpathResult) {
            return;
        }

        const toRemove = [];
        var textBlock = null;
        while ((textBlock = xpathResult.iterateNext()) !== null) {
            var node = textBlock;

            // check that we have one class name that starts with 'qu-' and ends with '--small'
            const smallClassCount = Array.from(node.classList).filter(c => c.startsWith('qu-') && c.endsWith('--small')).length;
            if (smallClassCount == 0) {
                continue; // Couldn't find qu-*--small class
            }

            // find the first parent node without classname
            do {
                node = node.parentNode;
            } while (node && node.className);
            // find the first parent node with classname, this is the block we want to remove
            do {
                node = node.parentNode;
            } while (node && !node.className);
            if (node && node.parentNode) {
                toRemove.push(node);
            }
        }

        // we need to remove the nodes after the XPath loop, otherwise it might fail due to the DOM changes happening concurrently
        for (const node of toRemove) {
            logRemovalsToDevConsole && console.log('Removing promoted block', node);
            node.remove();
        }
    }, 200); // repeat as more results are loaded (every 200ms)
})();