Remove promoted questions and answers on Quora

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

  1. // ==UserScript==
  2. // @name Remove promoted questions and answers on Quora
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Removes promoted answers that have nothing to do with the question you're looking up
  6. // @author https://gf.qytechs.cn/en/users/728793-keyboard-shortcuts
  7. // @match https://www.quora.com/*
  8. // @match https://quora.com/*
  9. // @icon https://www.google.com/s2/favicons?domain=quora.com&sz=128
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. /* jshint esversion: 6 */
  15.  
  16. (function() {
  17. 'use strict';
  18. var logRemovalsToDevConsole = false; // Change this to true to log removals to the console
  19.  
  20. function selectNodesWithXpath(selector) {
  21. const xpathResult = document.evaluate(selector, document, null, XPathResult.ANY_TYPE, null);
  22.  
  23. const elements = [];
  24. var curElement;
  25. while (xpathResult && (curElement = xpathResult.iterateNext()) !== null) {
  26. elements.push(curElement);
  27. }
  28. return elements;
  29. }
  30.  
  31. setInterval(function() {
  32. const removedClass = '__quora_ad_removed__';
  33.  
  34. // search for the "Promoted" or "Sponsored" string in a block with a small font ("q-text" or "q-click-wrapper")
  35. 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')]`);
  36.  
  37. const toRemove = [];
  38. var textBlock = null;
  39. for (const textBlock of elements) {
  40. var node = textBlock;
  41.  
  42. // find the first parent node with a class containing the string "Card_", this is the block we want to hide
  43. do {
  44. node = node.parentNode;
  45. } while (node && (node.className || '').indexOf('Card_') === -1);
  46.  
  47. if (node) { // found!
  48. if (logRemovalsToDevConsole) {
  49. console.log('Removing promoted block', node);
  50. }
  51. textBlock.classList.add(removedClass); // avoid picking up the same ad on the next page scan
  52. node.style.display = 'none';
  53. }
  54. }
  55. }, 250); // repeat as more results are loaded (every 250ms)
  56. })();

QingJ © 2025

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