Greasy Fork

Greasy Fork is available in English.

Yahoo News Filter

yahooニュースで任意の記事を非表示にする

当前为 2023-01-09 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           Yahoo News Filter
// @description    yahooニュースで任意の記事を非表示にする
// @grant          none
// @author         TNB
// @match          https://www.yahoo.co.jp
// @match          https://news.yahoo.co.jp/*
// @match          https://article.yahoo.co.jp/*
// @version        1.0.1
// @run-at         document-start
// @namespace http://greasyfork.icu/users/3989
// ==/UserScript==

/********************  SETTING **************************/

  const case_insensitive = true;
  const match_fullwidth = true;
  const filterWords = [];

/********************************************************/

'use strict';

(function() {

  const mod = case_insensitive? 'i': null;
  const p = new RegExp(filterWords.join('|'), mod);

  function convertHalfSize(str) {
    if (match_fullwidth) return str.replace(/[A-Za-z0-9]/g, s => String.fromCharCode(s.charCodeAt(0) - 65248));
    return str;
  }

  function removeArticle(d) {
    const a = d.querySelectorAll('[id^="tabpanelTopics"] ul>li, #Stream article, [id^="uamods"] li, ul[class$="list"] li, .yjnSub_list_item, .subList_item');
    for (const title of a) {
      if (p.test(convertHalfSize(title.textContent))) title.style.display = 'none';
    }
  }

  function observer() {
    const b = document.querySelectorAll('.mainColumn, .subColumn, #Topics, #qurireco, #contentsWrap, #yjnSub');
    if (!b) return;

    const mo = new MutationObserver(m => {
      for (const i of m) {
        removeArticle(i.target);
      }
    });
    for (const i of b) {
      mo.observe(i, {childList: true, subtree: true, attributeFilter: ['id']});
    }
  }

  window.addEventListener('DOMContentLoaded', () => {
    removeArticle(document);
    observer();
  });
})();