YouTube Split-Scroll Killer

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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

})();