Greasy Fork is available in English.

YouTube Split-Scroll Killer

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

})();