Greasy Fork

Greasy Fork is available in English.

Youtube 搜索过滤

从 Youtube 搜索页面移除特定用户上传的视频结果

当前为 2021-04-06 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* cspell:disable pixelmon */

// ==UserScript==
// @version      1.2.2
// @name         Youtube Search Filter
// @name:zh-CN   Youtube 搜索过滤
// @namespace    https://tools.unoiou.com
// @author       Mingshi
// @description  Remove garbage videos from Youtube search result page.
// @description:zh-CN 从 Youtube 搜索页面移除特定用户上传的视频结果
// @copyright    2020, Mingshi
// @license      MIT

// @require      https://openuserjs.org/src/libs/sizzle/GM_config.min.js
// @require      http://greasyfork.icu/scripts/374849-library-onelementready-es6/code/Library%20%7C%20onElementReady%20ES6.js?version=649483

// @match        https://www.youtube.com/results?*
// @match        https://www.youtube.com
// ==/UserScript==
// jshint esversion:6
/* global onElementReady */

// read blocklist keywords
const configName = 'ytd-search-block-list';
GM_config.init({
  'id': configName,
  'title': 'Youtube Search Filtr Setting',
  'fields': {
    'blocklist': {
      'label': 'Block List',
      'type': 'textarea',
      'default': '',
      'title': 'Each line represents a keyword of block list.'
    }
  },
  'css': [
      '#ytd-search-block-list_field_blocklist {min-height: 400px;}'
  ]
})
// add config btn
var button = document.createElement('button');
button.innerHTML = "Search Filter";
button.style = "bottom:1em;right:1em;position:fixed;z-index: 9999;background:red;";
button.setAttribute('type', 'button');
button.addEventListener('click', function () {
  GM_config.open();
}, false);
document.body.appendChild(button);

const keywords = GM_config.get('blocklist').split('\n').filter(e => e.length > 0);

// for easy debug
unsafeWindow.onElementReady = onElementReady;

// runs on each time `ytd-video-renderer` loaded.
onElementReady('ytd-video-renderer', false, (el) => {
  keywords.forEach((keyword) => {
    if (el.querySelector('ytd-channel-name').textContent.toLowerCase().includes(keyword)) {
      el.remove();
      console.log('removed', keyword);
    }
  });
});