YouTube Split-Scroll Killer

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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

})();