Youtube Shorts Garbage Remover

Hides elements based on like count conditions. Removes the trash tier garbage youtube shorts shoveled down your throat.

目前為 2023-05-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Youtube Shorts Garbage Remover
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Hides elements based on like count conditions. Removes the trash tier garbage youtube shorts shoveled down your throat.
// @author       psyda#0001 (but actually ChatGPT4)
// @match        *://www.youtube.com/*
// @license MIT
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    if (!window.location.pathname.startsWith('/shorts/')) {
        return;
    }

    const shouldHideElement = (likeCountText) => {
        return (/\d/.test(likeCountText) && !likeCountText.includes('k') && !likeCountText.includes('m')) || likeCountText === 'like';
    };

    const checkAndHideElement = (element) => {
        const likeButton = element.querySelector('#like-button');

        if (likeButton) {
            const likeCountSpan = likeButton.querySelector('span.yt-core-attributed-string.yt-core-attributed-string--white-space-pre-wrap.yt-core-attributed-string--text-alignment-center.yt-core-attributed-string--word-wrapping[role="text"]');

            if (likeCountSpan) {
                const likeCountText = likeCountSpan.textContent.toLowerCase();

                if (shouldHideElement(likeCountText)) {
                    // Find the video title
                    const videoTitleElement = element.querySelector('h2.title.style-scope.ytd-reel-player-header-renderer yt-formatted-string.style-scope.ytd-reel-player-header-renderer');
                    const videoTitle = videoTitleElement ? videoTitleElement.textContent : '';

                    // Mark the element as hidden if video title exists and is not empty
                    if (videoTitle.trim() !== '') {
                        // Hide the element and log the information
                        element.style.display = 'none';
                        element.setAttribute('data-hidden', 'true');

                        // Increment and log the total count of videos skipped
                        const totalSkipped = GM_getValue('totalSkipped', 0) + 1;
                        GM_setValue('totalSkipped', totalSkipped);
                        console.log(`GarbageShort_remover Deleted: "${videoTitle}" with "${likeCountText}" Likes. Saving you time. (Total skipped: ${totalSkipped})`);
                    }
                } else {
                    setTimeout(() => checkAndHideElement(element), 1500);
                }
            }
        }
    };

    const hideElements = () => {
        const elements = document.querySelectorAll('.reel-video-in-sequence.style-scope.ytd-shorts[is-active=""]');

        elements.forEach(element => {
            // Skip the element if it has already been hidden
            if (element.hasAttribute('data-hidden')) {
                return;
            }

            checkAndHideElement(element);
        });
    };

    const observeContainer = () => {
        const targetNode = document.querySelector('#shorts-inner-container');

        if (targetNode) {
            const observerConfig = { childList: true, subtree: true };
            const observerCallback = (mutationsList, observer) => {
                setTimeout(hideElements, 500); // Add a delay of 500 milliseconds
            };
            const observer = new MutationObserver(observerCallback);
            observer.observe(targetNode, observerConfig);
        } else {
            setTimeout(observeContainer, 1500);
        }
    };

    setTimeout(observeContainer, 2500);
})();

QingJ © 2025

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