Rutube - Block Autoplay

Blocks video autoplay on Rutube and in embed players by freezing the player's autoplay behavior.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Rutube - Block Autoplay
// @name:ru      Rutube - Блокировка автовоспроизведения
// @namespace    rutube-block-autoplay
// @version      1.0
// @description  Blocks video autoplay on Rutube and in embed players by freezing the player's autoplay behavior.
// @description:ru     Блокирует автозапуск видео на сайте Rutube и во встроенных плеерах через заморозку автозапуска плеера.
// @author       Vikindor (https://vikindor.github.io/)
// @homepageURL  https://github.com/Vikindor/rutube-block-autoplay
// @supportURL   https://github.com/Vikindor/rutube-block-autoplay/issues
// @license      MIT
// @match        https://rutube.ru/video/*
// @match        https://rutube.ru/play/embed/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    const observer = new MutationObserver((mutations, obs) => {
        const video = document.querySelector('video');
        if (video) {
            video.pause();
            video.autoplay = false;
            video.removeAttribute('autoplay');

            const originalPlay = video.play;
            let firstCall = true;

            video.play = function (...args) {
                if (firstCall) {
                    firstCall = false;
                    return Promise.reject('Autoplay prevented');
                }
                return originalPlay.apply(this, args);
            };

            obs.disconnect();
        }
    });

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