Remove promoted questions and answers on Quora

Removes promoted answers that have nothing to do with the question you're looking up

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Remove promoted questions and answers on Quora
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Removes promoted answers that have nothing to do with the question you're looking up
// @author       https://greatest.deepsurf.us/en/users/728793-keyboard-shortcuts
// @match        https://www.quora.com/*
// @match        https://quora.com/*
// @icon         https://www.google.com/s2/favicons?domain=quora.com&sz=128
// @grant        none
// @license      MIT
// ==/UserScript==

/* jshint esversion: 6 */

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

    function selectNodesWithXpath(selector) {
        const xpathResult = document.evaluate(selector, document, null, XPathResult.ANY_TYPE, null);

        const elements = [];
        var curElement;
        while (xpathResult && (curElement = xpathResult.iterateNext()) !== null) {
            elements.push(curElement);
        }
        return elements;
    }

    setInterval(function() {
        const removedClass = '__quora_ad_removed__';

        // search for the "Promoted" or "Sponsored" string in a block with a small font ("q-text" or "q-click-wrapper")
        const elements = selectNodesWithXpath(`//div[(contains(@class, 'q-text') or contains(@class, 'q-click-wrapper')) and (not(contains(@class, '${removedClass}'))) and (text() = 'Promoted' or text() = 'Sponsored')]`);

        const toRemove = [];
        var textBlock = null;
        for (const textBlock of elements) {
            var node = textBlock;

            // find the first parent node with a class containing the string "Card_", this is the block we want to hide
            do {
                node = node.parentNode;
            } while (node && (node.className || '').indexOf('Card_') === -1);

            if (node) { // found!
                if (logRemovalsToDevConsole) {
                    console.log('Removing promoted block', node);
                }
                textBlock.classList.add(removedClass); // avoid picking up the same ad on the next page scan
                node.style.display = 'none';
            }
        }
    }, 250); // repeat as more results are loaded (every 250ms)
})();