Remove promoted questions and answers on Quora

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

目前为 2021-09-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         Remove promoted questions and answers on Quora
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Removes promoted answers that have nothing to do with the question you're looking up
// @author       https://gf.qytechs.cn/en/users/728793-keyboard-shortcuts
// @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" string in a block with a small font
        var xpathResult = document.evaluate("//div[contains(@class, '--small') and (contains(., 'Promoted by') or contains(., 'Sponsored by'))]", 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 with a CssComponent class, this is the block we want to remove
            do {
                node = node.parentNode;
            } while (node && node.className && node.className.indexOf('CssComponent') == -1);
            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)
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址