YouTube Split-Scroll Killer

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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 });

})();