Removes promoted answers that have nothing to do with the question you're looking up
当前为
// ==UserScript==
// @name Remove promoted questions and answers on Quora
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Removes promoted answers that have nothing to do with the question you're looking up
// @author https://greasyfork.org/en/users/728793-keyboard-shortcuts
// @match https://www.quora.com/*
// @match https://quora.com/*
// @icon https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://quora.com&size=64
// @grant none
// @license MIT
// ==/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
}
// make sure there are no <div> elements inside; we're only looking for the small label "promoted by *whatever*".
if (node.querySelector('div') !== null) {
continue; // this isn't the one we're looking for, it could be a parent of it.
}
// 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)
})();