YouTube Split-Scroll Killer

Removes the annoying split-scroll feature and restores the classic secondary stream scroll behavior.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         YouTube Split-Scroll Killer
// @name:en      YouTube Split-Scroll Killer
// @name:ru      YouTube Split-Scroll Killer
// @namespace    yt-debug
// @version      1.0
// @description  Removes the annoying split-scroll feature and restores the classic secondary stream scroll behavior.
// @description:en Removes the annoying split-scroll feature and restores the classic secondary stream scroll behavior.
// @description:ru Удаляет раздражающую функцию split-scroll и возвращает классический поток прокрутки вторичного контента.
// @author       Alina Novikova
// @match        https://www.youtube.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 1. ПОДМЕНА ВЕРСИИ КЛИЕНТА (Сервер подумает, что мы со старого браузера)
    const oldVersion = "2.20230601.01.00";

    const patchObj = (obj) => {
        if (!obj) return;
        if (obj.INNERTUBE_CONTEXT_CLIENT_VERSION) obj.INNERTUBE_CONTEXT_CLIENT_VERSION = oldVersion;
        if (obj.clientVersion) obj.clientVersion = oldVersion;
        if (obj.EXPERIMENT_FLAGS) {
            obj.EXPERIMENT_FLAGS.kevlar_watch_metadata_refresh = false;
            obj.EXPERIMENT_FLAGS.kevlar_watch_metadata_refresh_no_old_secondary_data = false;
            obj.EXPERIMENT_FLAGS.web_watch_use_sidebar_width_percentage = false;
        }
    };

    // Перехватываем конфигурацию до инициализации
    if (window.ytcfg) {
        const originalSet = window.ytcfg.set;
        window.ytcfg.set = function(key, val) {
            if (key === 'EXPERIMENT_FLAGS') patchObj({EXPERIMENT_FLAGS: val});
            return originalSet.apply(this, arguments);
        };
    }

    // 2. ЖЕСТКИЙ CSS ДЛЯ УБИЙСТВА SPLIT-SCROLL И GRID
    const css = `
        /* Отключаем фиксированный сайдбар */
        ytd-watch-flexy[split-scroll] #secondary.ytd-watch-flexy {
            position: static !important;
            width: 400px !important;
            margin-top: 0 !important;
        }
        ytd-watch-flexy[split-scroll] #secondary-inner.ytd-watch-flexy {
            position: static !important;
            width: 400px !important;
        }
        /* Возвращаем нормальный скролл страницы */
        body, html {
            overflow: auto !important;
        }
        /* Убираем закругления у кнопок */
        .yt-spec-button-shape-next--filled, .yt-spec-button-shape-next--outline {
            border-radius: 2px !important;
        }

    `;

    const styleSheet = document.createElement("style");
    styleSheet.textContent = css;
    document.documentElement.appendChild(styleSheet);

    // 3. УДАЛЕНИЕ АТРИБУТОВ "НОВОГО ДИЗАЙНА" В РЕАЛЬНОМ ВРЕМЕНИ
    const cleanLayout = () => {
        const player = document.querySelector('ytd-watch-flexy');
        if (player) {
            // Удаляем маркеры, по которым ориентируются скрипты YouTube
            if (player.hasAttribute('split-scroll')) player.removeAttribute('split-scroll');
            if (player.hasAttribute('metadata-refresh')) player.removeAttribute('metadata-refresh');
            if (player.hasAttribute('watch-grid')) player.removeAttribute('watch-grid');
        }
    };

    const observer = new MutationObserver(cleanLayout);
    observer.observe(document.documentElement, { attributes: true, subtree: true });

})();