YouTube Focus

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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 });
    }
})();