Yahoo Answers Trash Filter

Hide Yahoo Answers questions matching a list of words

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Yahoo Answers Trash Filter
// @version      0.1
// @description  Hide Yahoo Answers questions matching a list of words
// @include      http://answers.yahoo.com/*
// @include      https://answers.yahoo.com/*
// @author       tlacuache
// @namespace https://greasyfork.org/users/688118
// ==/UserScript==

(function() {
  'use strict';

  function getDivsByRegex(regex) {
    var divs = document.getElementsByTagName('div'),
        matches = [],
        index,
        div;
    for (index = 0; index < divs.length; index += 1) {
      div = divs[index];
      if (regex.test(div.className)) {
        matches.push(div);
      }
    }
    return matches;
  }

  function cleanIt() {
    var questionCards = getDivsByRegex(/^QuestionCard__/),
      i, j, k,
      card, child, grandChild,
      hideme, questionText,
      hideCount = 0,
      skipRegex = /\b(trump|kamala|harris|pelosi|donald|blm|obama|clinton|biden|corona|coronavirus|covid\d*|conservatives?|liberals?|libtards?|dems?|democrats?|republicans?|coronavirus)\b/i;

    for (i = 0; i < questionCards.length; i += 1) {
      card = questionCards[i];
        if (card.parentNode.style.display != 'none') {
        hideme = false;
        for (j = 0; j < card.childNodes.length; j += 1) {
          child = card.childNodes[j];
          for (k = 0; k < child.childNodes.length; k += 1) {
            grandChild = child.childNodes[k];
            if (/^QuestionCard__title__/.test(grandChild.className)) {
              questionText = grandChild.textContent;
              if (skipRegex.test(questionText)) {
                hideme = true;
                break;
              }
            }
            if (hideme) break;
          }
          if (hideme) break;
        }
        if (hideme) {
          card.parentNode.style.display = 'none';
          hideCount++;
        }
      }
    }
    // if (hideCount > 0) console.log('hid', hideCount, 'garbage questions');
  }

  document.addEventListener('DOMNodeInserted', cleanIt, false);

  cleanIt();

})();