YouTube Layout Enhancer & Search Focus

Melhora o layout do YouTube, organiza conteúdo e filtra resultados de pesquisa

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         YouTube Layout Enhancer & Search Focus
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Melhora o layout do YouTube, organiza conteúdo e filtra resultados de pesquisa
// @author       EmersonxD
// @match        *://*.youtube.com/*
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Estilos CSS personalizados
    GM_addStyle(`
        /* Layout Geral */
        #page-manager {
            max-width: 1400px !important;
            margin: 0 auto !important;
            padding: 20px !important;
        }

        /* Grade de Vídeos */
        ytd-rich-grid-row {
            justify-content: center !important;
            gap: 20px !important;
            margin: 30px 0 !important;
        }

        ytd-rich-item-renderer {
            width: 300px !important;
            margin: 10px !important;
            border-radius: 8px !important;
            transition: transform 0.2s !important;
        }

        ytd-rich-item-renderer:hover {
            transform: translateY(-5px) !important;
        }

        /* Barra de Pesquisa */
        #search-container {
            max-width: 800px !important;
            margin: 0 auto !important;
        }

        /* Filtro de Conteúdo */
        .secondary-content {
            display: none !important;
        }

        /* Paginação */
        #pagination-container {
            display: flex !important;
            justify-content: center !important;
            margin: 40px 0 !important;
            gap: 15px !important;
        }

        .pagination-btn {
            padding: 8px 16px !important;
            border-radius: 4px !important;
            background: #f0f0f0 !important;
            cursor: pointer !important;
        }
    `);

    // Filtro de Pesquisa Aprimorado
    const applySearchFilter = () => {
        const searchQuery = new URLSearchParams(window.location.search).get('search_query')?.toLowerCase();
        if (!searchQuery) return;

        document.querySelectorAll('ytd-video-renderer, ytd-rich-item-renderer').forEach(video => {
            const title = video.querySelector('#video-title')?.textContent.toLowerCase();
            const match = title?.includes(searchQuery);
            video.style.display = match ? 'block' : 'none';
        });
    };

    // Sistema de Paginação
    const createPagination = () => {
        const container = document.createElement('div');
        container.id = 'pagination-container';
        
        ['Anterior', '1', '2', '3', 'Próximo'].forEach(text => {
            const btn = document.createElement('button');
            btn.className = 'pagination-btn';
            btn.textContent = text;
            container.appendChild(btn);
        });

        const mainContent = document.querySelector('ytd-app');
        if (mainContent) mainContent.appendChild(container);
    };

    // Observador de Mudanças Dinâmicas
    const observer = new MutationObserver(mutations => {
        if (window.location.pathname === '/results') {
            applySearchFilter();
            createPagination();
        }
    });

    // Inicialização
    window.addEventListener('load', () => {
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        if (window.location.pathname === '/results') {
            applySearchFilter();
            createPagination();
        }
    });

    // Hotkey para Recarregar Filtros (Ctrl + Shift + F)
    document.addEventListener('keydown', (e) => {
        if (e.ctrlKey && e.shiftKey && e.key === 'F') {
            applySearchFilter();
        }
    });
})();