Greasy Fork

YouTube Thumbnail Hider & Shorts Remover

Hide video thumbnails on YouTube and remove Shorts sections with configurable options.

安装此脚本?
作者推荐脚本

您可能也喜欢X Timeline Sync

安装此脚本
// ==UserScript==
// @name         YouTube Thumbnail Hider & Shorts Remover
// @namespace    http://tampermonkey.net/
// @version      2025-02-28
// @description  Hide video thumbnails on YouTube and remove Shorts sections with configurable options.
// @description:de  Blende Video-Thumbnails auf YouTube aus und entferne Shorts-Bereiche mit konfigurierbaren Optionen.
// @description:es  Oculta miniaturas de video en YouTube y elimina secciones de Shorts con opciones configurables.
// @description:fr  Masquer les miniatures de vidéos sur YouTube et supprimer les sections Shorts avec des options configurables.
// @author       Copiis
// @match        https://www.youtube.com/feed/subscriptions
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// @license      MIT
// @icon         https://www.youtube.com/favicon.ico
// ==/UserScript==
//                    If you find this script useful and would like to support my work, consider making a small donation!
//                    Bitcoin (BTC): bc1quc5mkudlwwkktzhvzw5u2nruxyepef957p68r7
//                    PayPal: https://www.paypal.com/paypalme/Coopiis?country.x=DE&locale.x=de_DE

(function() {
    'use strict';

    const LANGUAGES = {
        en: {
            'settingsUpdated': 'Settings updated. Refresh the page to apply changes.',
            'show': 'visible',
            'hide': 'hidden',
            'language': 'Select Language',
            'showShorts': 'Show Shorts',
            'hideShorts': 'Hide Shorts'
        },
        de: {
            'settingsUpdated': 'Einstellungen aktualisiert. Seite neu laden, um Änderungen anzuwenden.',
            'show': 'sichtbar',
            'hide': 'versteckt',
            'language': 'Sprache wählen',
            'showShorts': 'Shorts einblenden',
            'hideShorts': 'Shorts ausblenden'
        },
        es: {
            'settingsUpdated': 'Configuración actualizada. Recarga la página para aplicar los cambios.',
            'show': 'visibles',
            'hide': 'ocultos',
            'language': 'Seleccionar idioma',
            'showShorts': 'Mostrar Shorts',
            'hideShorts': 'Ocultar Shorts'
        },
        fr: {
            'settingsUpdated': 'Paramètres mis à jour. Rafraîchissez la page pour appliquer les changements.',
            'show': 'visibles',
            'hide': 'cachés',
            'language': 'Sélectionner la langue',
            'showShorts': 'Afficher les Shorts',
            'hideShorts': 'Masquer les Shorts'
        }
    };

    let settings = JSON.parse(localStorage.getItem('ytHiderSettings') || '{"hideShorts": true, "language": "auto"}');
    let userLang = settings.language === 'auto' ? (navigator.language.split('-')[0] || 'en') : settings.language;
    if (!LANGUAGES[userLang]) userLang = 'en';

    function registerShortsMenu() {
        GM_registerMenuCommand(LANGUAGES[userLang].hideShorts, () => {
            settings.hideShorts = true;
            localStorage.setItem('ytHiderSettings', JSON.stringify(settings));
            manageShortsVisibility();
        });
        GM_registerMenuCommand(LANGUAGES[userLang].showShorts, () => {
            settings.hideShorts = false;
            localStorage.setItem('ytHiderSettings', JSON.stringify(settings));
            manageShortsVisibility();
        });
    }

    registerShortsMenu();
    GM_registerMenuCommand(LANGUAGES[userLang].language, selectLanguage);

    const observer = new MutationObserver(addEyeToThumbnails);
    observer.observe(document.body, { childList: true, subtree: true });

    const hiddenVideos = JSON.parse(localStorage.getItem('hiddenVideos') || '{}');

    function addEyeToThumbnails() {
        document.querySelectorAll('ytd-grid-video-renderer, ytd-rich-item-renderer').forEach(video => {
            const videoId = video.querySelector('a#thumbnail')?.href?.split('v=')[1];
            if (!videoId) return;

            if (hiddenVideos[videoId]) {
                video.style.display = 'none';
                return;
            }

            const thumbnailContainer = video.querySelector('#thumbnail');
            if (!thumbnailContainer || thumbnailContainer.querySelector('.eye-icon')) return;

            const eye = document.createElement('div');
            eye.textContent = '👁️';
            eye.classList.add('eye-icon');
            eye.style.position = 'absolute';
            eye.style.left = '8px';
            eye.style.bottom = '8px';
            eye.style.fontSize = '24px';
            eye.style.cursor = 'pointer';
            eye.style.zIndex = '10';
            eye.dataset.persistent = 'true';

            eye.addEventListener('click', (e) => {
                e.preventDefault();
                e.stopPropagation();
                triggerHideVideo(video);
            });

            thumbnailContainer.style.position = 'relative';
            thumbnailContainer.appendChild(eye);
        });

        document.querySelectorAll('.eye-icon').forEach(eye => {
            if (!eye.dataset.persistent) {
                eye.remove();
            }
        });

        manageShortsVisibility();
    }

    function triggerHideVideo(video) {
        const menuIcon = video.querySelector('ytd-menu-renderer .yt-icon-shape');
        if (!menuIcon) return;

        menuIcon.click();

        setTimeout(() => {
            const popup = document.querySelector('ytd-menu-popup-renderer');
            if (popup) {
                const hideItem = Array.from(popup.querySelectorAll('ytd-menu-service-item-renderer'))
                    .find(item => item.querySelector('yt-formatted-string')?.textContent.trim() === 'Ausblenden');
                if (hideItem) {
                    hideItem.click(); // Direkter Klick auf das Menü-Item sollte das Popup schließen
                } else {
                    const videoId = video.querySelector('a#thumbnail')?.href?.split('v=')[1];
                    if (videoId) {
                        hiddenVideos[videoId] = true;
                        localStorage.setItem('hiddenVideos', JSON.stringify(hiddenVideos));
                        video.style.display = 'none';
                    }
                }
            }
        }, 150);
    }

    function manageShortsVisibility() {
        document.querySelectorAll('ytd-rich-section-renderer').forEach(section => {
            if (section.querySelector('#title')?.textContent.includes('Shorts')) {
                section.style.display = settings.hideShorts ? 'none' : 'block';
            }
        });
    }

    function selectLanguage() {
        const langChoice = prompt(LANGUAGES[userLang].language + '\n\n' + Object.keys(LANGUAGES).join(', ').toUpperCase(), userLang.toUpperCase());
        if (langChoice && LANGUAGES[langChoice.toLowerCase()]) {
            settings.language = langChoice.toLowerCase();
            localStorage.setItem('ytHiderSettings', JSON.stringify(settings));
            userLang = settings.language;
            alert(LANGUAGES[userLang].settingsUpdated);
            registerShortsMenu();
        } else {
            alert('Invalid language choice.');
        }
    }

    manageShortsVisibility();
})();