YouTube Focus

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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 });
    }
})();