YouTube Restart Video Button

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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