YT Channel Query Fix

Remove external (channel) videos in queries.

目前為 2019-08-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name         YT Channel Query Fix
// @namespace    youtube.scripts
// @version      1.2
// @description  Remove external (channel) videos in queries.
// @include      *.youtube.com/*search*
// ==/UserScript==

(function() {
    'use strict';

    const INTERVAL = 500;
    const MAX_HITS = 4; /* There are only 4 */

    const this_channel = location.href.match(/(.*)\//)[1];
    var hits = 0;
    var id = setInterval(() => {
        let ns = document.querySelectorAll("ytd-item-section-renderer");
        for(let e of ns) {
            let a = e.querySelector("#metadata a");
            if(!e.hidden && a.href != this_channel) {
                e.hidden = true;
                hits = hits + 1;
                if(hits >= MAX_HITS) {
                    clearInterval(id);
                    break;
                }
            }
        }
    }, INTERVAL);
})();