YouTube - Remove YouTube shorts from subscriptions

YouTube - Remove YouTube shorts from subscriptions list

目前为 2022-06-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         YouTube - Remove YouTube shorts from subscriptions
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  YouTube - Remove YouTube shorts from subscriptions list
// @author       jez
// @match        *://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    var utils = {};
    utils.jq = jQuery.noConflict( true );

    // Add 'hidden renderer' class
    var sheet = document.createElement('style');
    sheet.innerHTML = ".hiddenRenderer {display: none!important;}";
    document.body.appendChild(sheet);

    // Observe DOM mutations for when 'shorts' video renderer is added and whenever it is, hide it
    var config = {
        attributes: true,
        childList: true,
        characterData: true,
        subtree: true
    };
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes && mutation.addedNodes.length > 0) {
                [].forEach.call(mutation.addedNodes, function(el) {
                    // YouTube first creates the video-renderer, then tacks on the 'shorts' overlay; so instead of finding the mutation that adds
                    // the video-renderer, we find the mutation that adds on the 'shorts' overlay, then travel up to its video-renderer parent,
                    // and hide it at that point.
                    var $addedNode = utils.jq(el);
                    var tagName = $addedNode.prop("tagName");
                    if (tagName && tagName.toLowerCase() == 'ytd-thumbnail-overlay-time-status-renderer' && $addedNode.attr('overlay-style') == "SHORTS") {
                        // Travel up to video-renderer parent and hide it
                        $addedNode.parents('ytd-grid-video-renderer').addClass('hiddenRenderer');
                    }
                });
            }
        });
    });
    observer.observe(document.body, config);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址