YouTube Focus

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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