🏠 返回首頁 

Greasy Fork is available in English.

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://greasyfork.org/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. /* jshint esversion: 6 */
  14. (function() {
  15. 'use strict';
  16. var logRemovalsToDevConsole = false; // Change this to true to log removals to the console
  17. function selectNodesWithXpath(selector) {
  18. const xpathR###lt = document.evaluate(selector, document, null, XPathR###lt.ANY_TYPE, null);
  19. const elements = [];
  20. var curElement;
  21. while (xpathR###lt && (curElement = xpathR###lt.iterateNext()) !== null) {
  22. elements.push(curElement);
  23. }
  24. return elements;
  25. }
  26. setInterval(function() {
  27. const removedClass = '__quora_ad_removed__';
  28. // search for the "Promoted" or "Sponsored" string in a block with a small font ("q-text" or "q-click-wrapper")
  29. 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')]`);
  30. const toRemove = [];
  31. var textBlock = null;
  32. for (const textBlock of elements) {
  33. var node = textBlock;
  34. // find the first parent node with a class containing the string "Card_", this is the block we want to hide
  35. do {
  36. node = node.parentNode;
  37. } while (node && (node.className || '').indexOf('Card_') === -1);
  38. if (node) { // found!
  39. if (logRemovalsToDevConsole) {
  40. console.log('Removing promoted block', node);
  41. }
  42. textBlock.classList.add(removedClass); // avoid picking up the same ad on the next page scan
  43. node.style.display = 'none';
  44. }
  45. }
  46. }, 250); // repeat as more r###lts are loaded (every 250ms)
  47. })();