YouTube Restart Video Button

Добавляет кнопку для возврата видео на начало.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         YouTube Restart Video Button
// @namespace    https://github.com/ToLIManl
// @version      0.7
// @description  Добавляет кнопку для возврата видео на начало.
// @description:ru  Добавляет кнопку для возврата видео на начало.
// @description:en  Adds the video return button to the beginning.
// @author       ToLIMan
// @match        https://www.youtube.com/*
// @grant        none
// @license         MIT
// @name:ru         Кнопка воспроизвести видео сначала Youtube
// @name:en         YouTube Restart Video Button
// ==/UserScript==

(function() {
    'use strict';

    // Функция для создания кнопки
    function addRestartButton() {
        const controls = document.querySelector('.ytp-left-controls'); // Панель управления YouTube
        if (!controls || document.querySelector('#restart-button')) return; // Проверка наличия панели и кнопки

        // Создание кнопки
        const button = document.createElement('button');
        button.id = 'restart-button';
        button.textContent = '⏪'; // Иконка кнопки
        button.title = 'Вернуть на начало';
        button.style.cssText = `
            background: none;
            border: none;
            color: white;
            font-size: 16px;
            cursor: pointer;
            padding: 0 10px;
        `;

        // Добавление обработчика нажатия
        button.addEventListener('click', () => {
            const video = document.querySelector('video');
            if (video) {
                video.currentTime = 0; // Устанавливаем время на 0
            }
        });

        // Добавление кнопки в панель управления
        controls.insertBefore(button, controls.firstChild);
    }

    // Наблюдатель для динамического добавления кнопки
    const observer = new MutationObserver(() => {
        addRestartButton();
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();