YouTube Focus

Убирает отвлекающие элементы

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         YouTube Focus
// @namespace    https://greasyfork.org/ru/scripts/570463-youtube-focus
// @author       4c5688
// @license      CC BY-SA
// @version      1.2
// @description  Убирает отвлекающие элементы
// @match        https://www.youtube.com/*
// @match        https://m.youtube.com/*
// @run-at       document-idle
// @grant        none
// @icon         https://favicon.yandex.net/favicon/youtube.com
// ==/UserScript==

(function() {
    'use strict';

    const isMobile = location.hostname.startsWith('m.');

    if (isMobile) {
        if (location.pathname === '/') {
            window.location.replace('https://m.youtube.com/feed/library');
            return;
        }

        const style = document.createElement('style');
        style.textContent = `
            ytm-pivot-bar-renderer {
                display: none !important;
            }
            .related-items-container {
                display: none !important;
            }
        `;
        document.head.appendChild(style);

        function changeMobileLogo() {
            const logoBtn = document.querySelector('ytm-home-logo button');
            if (logoBtn && !logoBtn.dataset.fixed) {
                logoBtn.dataset.fixed = 'true';
                logoBtn.addEventListener('click', (e) => {
                    e.preventDefault();
                    e.stopPropagation();
                    window.location.href = 'https://m.youtube.com/feed/library';
                }, true);
            }
        }

        function hideMobileRecs() {
            document.querySelectorAll(
                '.related-items-container, ytm-item-section-renderer[section-identifier="related-items"]'
            ).forEach(el => el.remove());
        }

        const observerMobile = new MutationObserver(() => {
            changeMobileLogo();
            hideMobileRecs();
        });
        observerMobile.observe(document.body, { childList: true, subtree: true });

        changeMobileLogo();
        hideMobileRecs();

    } else {
        if (location.pathname === '/') {
            window.location.replace('https://www.youtube.com/feed/you');
            return;
        }

        function updateLinks() {
            const logo = document.querySelector('a#logo');
            if (logo) {
                logo.href = 'https://www.youtube.com/feed/you';
                logo.addEventListener('click', e => {
                    window.location.href = 'https://www.youtube.com/feed/you';
                });
            }

            const sidebarHome = document.querySelector('a#endpoint[title="Главная"]');
            if (sidebarHome) {
                sidebarHome.href = 'https://www.youtube.com/feed/you';
                sidebarHome.addEventListener('click', e => {
                    window.location.href = 'https://www.youtube.com/feed/you';
                });
            }
        }

        function hideRecommendationsAndAdjustLayout() {
            const recs = document.querySelectorAll('ytd-watch-next-secondary-results-renderer.style-scope');
            recs.forEach(block => block.style.display = 'none');

            const flexy = document.querySelector('ytd-watch-flexy.style-scope');
            if (flexy) {
                const playerContainer = flexy.querySelector('#secondary');
                if (playerContainer) playerContainer.style.display = 'none';

                const primary = flexy.querySelector('#primary');
                if (primary) primary.style.width = '100%';
            }
        }

        updateLinks();
        hideRecommendationsAndAdjustLayout();

        const observerDesktop = new MutationObserver(() => {
            updateLinks();
            hideRecommendationsAndAdjustLayout();
        });
        observerDesktop.observe(document.body, { childList: true, subtree: true });
    }
})();