YouTube Split

Устанавливает сплит по времени, выводит панель управления в clarify-box и, при достижении порога, показывает оверлей "СПЛИТ НЕ ОПЛАЧЕН" с кнопкой продления (+ 1 минута)

As of 09.02.2025. See апошняя версія.

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 
// @namespace    http://tampermonkey.net/
// @version      1.1
// @author       ChatGPT
// @match        *://www.youtube.com/watch*
// @grant        none
// @description Устанавливает сплит по времени, выводит панель управления в clarify-box и, при достижении порога, показывает оверлей "СПЛИТ НЕ ОПЛАЧЕН" с кнопкой продления (+ 1 минута)
// ==/UserScript==

(function() {
    'use strict';

    // Глобальные переменные
    let splitMinutes = null;    // Значение сплита в минутах
    let video = null;           // Элемент видео
    let overlay = null;         // Элемент оверлея
    let splitTriggered = false; // Флаг, что сплит активирован

    // Обновление отображения значения сплита в спинере
    function updateSplitDisplay() {
        const inputField = document.getElementById("split-input");
        if (inputField && splitMinutes !== null) {
            inputField.value = splitMinutes;
        }
    }

    // Создание панели управления сплитом внутри элемента "clarify-box"
    function addControlPanel() {
        const clarifyBox = document.getElementById("clarify-box");
        if (!clarifyBox) return;
        if (document.getElementById("split-control-panel")) return; // панель уже существует

        // Создаем контейнер панели (под тёмную тему)
        const panel = document.createElement("div");
        panel.id = "split-control-panel";
        panel.style.cssText = "margin-top: 10px; padding: 10px; background: #181818; border: 1px solid #373737; display: flex; align-items: center; gap: 10px; color: #fff;";

        // Кнопка "НАЧАТЬ СПЛИТ"
        const setButton = document.createElement("button");
        setButton.textContent = "НАЧАТЬ СПЛИТ";
        setButton.style.cssText = "padding: 5px 10px; font-size: 16px; cursor: pointer; background: #303030; color: #fff; border: 1px solid #444; border-radius: 4px;";
        setButton.addEventListener("click", function() {
            const inputField = document.getElementById("split-input");
            const inputVal = parseInt(inputField.value, 10);
            if (!isNaN(inputVal) && inputVal >= 0) {
                splitMinutes = inputVal;
                video.pause();       // Останавливаем видео
                splitTriggered = true;
                showOverlay();       // Показываем оверлей
            } else {
                alert("Введите корректное число минут.");
            }
        });

        // Метка "СПЛИТ (мин):"
        const label = document.createElement("span");
        label.textContent = "СПЛИТ (мин):";
        label.style.cssText = "font-size: 16px;";

        // Кнопка уменьшения (стрелка вниз)
        const decrementButton = document.createElement("button");
        decrementButton.textContent = "↓";
        decrementButton.style.cssText = "padding: 5px; font-size: 16px; cursor: pointer; background: #303030; color: #fff; border: 1px solid #444; border-radius: 4px;";
        decrementButton.addEventListener("click", function() {
            const inputField = document.getElementById("split-input");
            let currentVal = parseInt(inputField.value, 10);
            if (!isNaN(currentVal) && currentVal > 0) {
                inputField.value = currentVal - 1;
                updateSplitTime();
            }
        });

        // Поле ввода (spinner) для установки минут сплита
        const inputField = document.createElement("input");
        inputField.type = "number";
        inputField.id = "split-input";
        inputField.value = "0";
        inputField.min = "0";
        inputField.style.cssText = "width: 60px; text-align: center; font-size: 16px; background: #303030; color: #fff; border: 1px solid #444; border-radius: 4px;";
        inputField.addEventListener("change", updateSplitTime);

        // Кнопка увеличения (стрелка вверх)
        const incrementButton = document.createElement("button");
        incrementButton.textContent = "↑";
        incrementButton.style.cssText = "padding: 5px; font-size: 16px; cursor: pointer; background: #303030; color: #fff; border: 1px solid #444; border-radius: 4px;";
        incrementButton.addEventListener("click", function() {
            const inputField = document.getElementById("split-input");
            let currentVal = parseInt(inputField.value, 10);
            if (!isNaN(currentVal)) {
                inputField.value = currentVal + 1;
                updateSplitTime();
            }
        });

        // Собираем панель
        panel.appendChild(setButton);
        panel.appendChild(label);
        panel.appendChild(decrementButton);
        panel.appendChild(inputField);
        panel.appendChild(incrementButton);

        // Вставляем панель в "clarify-box"
        clarifyBox.appendChild(panel);
    }

    // Обновление значения сплита при изменении в спинере
    function updateSplitTime() {
        const inputField = document.getElementById("split-input");
        const newVal = parseInt(inputField.value, 10);
        if (!isNaN(newVal)) {
            splitMinutes = newVal;
            updateSplitDisplay();
            // Если видео остановлено из-за сплита и текущее время стало меньше нового порога,
            // убираем оверлей и продолжаем воспроизведение
            if (video && splitTriggered && video.currentTime < splitMinutes * 60) {
                video.play();
                splitTriggered = false;
                removeOverlay();
            }
        }
    }

    // Проверка времени видео – если текущее время достигло или превысило порог, останавливаем видео и показываем оверлей
    function checkSplitCondition() {
        if (!video || splitMinutes === null) return;
        const thresholdSeconds = splitMinutes * 60;
        if (video.currentTime >= thresholdSeconds && !splitTriggered) {
            video.pause();
            splitTriggered = true;
            showOverlay();
        }
        // Если сплит активирован, но пользователь увеличил его и текущее время стало меньше порога,
        // возобновляем воспроизведение
        if (splitTriggered && video.currentTime < thresholdSeconds) {
            video.play();
            splitTriggered = false;
            removeOverlay();
        }
    }

    // Функция показа полноэкранного оверлея с надписями
    function showOverlay() {
        if (overlay) return;
        overlay = document.createElement("div");
        overlay.style.cssText = `
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.95);
            color: white;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 99999;
        `;

        // Надпись с предупреждением
        const warningMessage = document.createElement("div");
        warningMessage.textContent = "⚠️ НУЖНО ДОНАТНОЕ ТОПЛИВО ⚠️";
        warningMessage.style.cssText = "font-size: 48px; margin-bottom: 20px;";

        // Надпись "СПЛИТ НЕ ОПЛАЧЕН"
        const splitMessage = document.createElement("div");
        splitMessage.textContent = "СПЛИТ НЕ ОПЛАЧЕН";
        splitMessage.style.cssText = "font-size: 64px; font-weight: bold; margin-bottom: 30px;";

        // Кнопка для продления сплита (увеличение на 1 минуту)
        const extendButton = document.createElement("button");
        extendButton.textContent = "+ 1 минута - 300 рублей";
        extendButton.style.cssText = "padding: 10px 20px; font-size: 24px; cursor: pointer; background: #ff4500; border: none; color: white; border-radius: 4px;";
        extendButton.addEventListener("click", function() {
            extendSplit();
        });

        // Собираем оверлей
        overlay.appendChild(warningMessage);
        overlay.appendChild(splitMessage);
        overlay.appendChild(extendButton);

        document.body.appendChild(overlay);
    }

    // Удаление оверлея
    function removeOverlay() {
        if (overlay) {
            overlay.remove();
            overlay = null;
        }
    }

    // Продление сплита – увеличение на 1 минуту
    function extendSplit() {
        if (splitMinutes === null) return;
        splitMinutes += 1;
        updateSplitDisplay();
        // Если текущее время стало меньше нового порога, убираем оверлей и продолжаем воспроизведение
        if (video.currentTime < splitMinutes * 60) {
            removeOverlay();
            video.play();
            splitTriggered = false;
        } else {
            alert("Продление недостаточно для продолжения воспроизведения. Продлите сплит ещё раз.");
        }
    }

    // Инициализация скрипта
    function init() {
        video = document.querySelector("video");
        if (!video) return;
        addControlPanel();
        setInterval(checkSplitCondition, 500);
    }

    // Ждем загрузки страницы
    setTimeout(init, 3000);
    setInterval(addControlPanel, 2000);
})();