YouTube, Filter Videos List

Filter the videos listed on a YouTube channel's videos page. Click "FILTER VIDEOS" next to "PLAY ALL" at the top of the videos list, then enter the string to search for. Start your entry with '!' to show only videos that DON'T contain that string.

当前为 2018-06-09 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube, Filter Videos List
// @namespace    driver8.net
// @version      0.1
// @description  Filter the videos listed on a YouTube channel's videos page. Click "FILTER VIDEOS" next to "PLAY ALL" at the top of the videos list, then enter the string to search for. Start your entry with '!' to show only videos that DON'T contain that string.
// @author       driver8
// @match        *://*.youtube.com/user/*/videos*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log('hi, filter videos');

    var filtered = [];

    var button_html = `<div id="load-more" class="style-scope ytd-channel-sub-menu-renderer">
<ytd-button-renderer button-renderer="" class="style-scope ytd-channel-sub-menu-renderer style-text" is-paper-button="">
<a class="yt-simple-endpoint style-scope ytd-button-renderer" tabindex="-1">
<paper-button role="button" tabindex="0" animated="" aria-disabled="false" elevation="0" id="button" class="style-scope ytd-button-renderer style-text">
Filter videos
</paper-button>
</a>
</ytd-button-renderer>
</div>`
    var new_div = document.createElement('div');
    new_div.innerHTML = button_html.trim();
    new_div = new_div.firstElementChild;
    var temp1 = new_div.firstElementChild.innerHTML;
    document.querySelector('#primary-items').appendChild(new_div);
    window.setTimeout(function test1() {
        new_div.firstElementChild.innerHTML = temp1;
    }, 20);
    new_div.onclick = filter_videos;

    function filter_videos() {
        var q = prompt('Enter word to filter', '');
        var neg = false;
        if (q.charAt(0) === '!') {
            neg = true;
            q = q.substr(1);
        }
        filtered.forEach(el => { el.hidden = false; });
        var vids = Array.from(document.querySelectorAll('#content #items > ytd-grid-video-renderer.ytd-grid-renderer'));
        var good = vids.filter(el => el.offsetParent !== null);
        var re = new RegExp(q, 'i');
        filtered = good.filter(el => {
            el.hidden = false;
            var title = el.querySelector('a#video-title').textContent;
            return neg ^ !re.test(title);
        });
        console.log('filtered', filtered);
        filtered.forEach(el => { el.hidden = true; });
    }
})();