Redditp Autoplay On Load (Mobile Ready)

Autoplays all videos on redditp.com, even when scrolling. Works in AdGuard on Android.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Redditp Autoplay On Load (Mobile Ready)
// @namespace    http://yourmomshouse.com/
// @version      1.3
// @description  Autoplays all videos on redditp.com, even when scrolling. Works in AdGuard on Android.
// @author       Your Friendly Script Goblin
// @match        *://redditp.com/*
// @run-at       document-end
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function autoplayVideos() {
        const videos = document.querySelectorAll('video:not([data-autoplayed])');
        videos.forEach(video => {
            const playPromise = video.play();
            if (playPromise !== undefined) {
                playPromise
                    .then(() => video.setAttribute('data-autoplayed', 'true'))
                    .catch(err => {
                        console.warn('Autoplay failed:', err);
                    });
            } else {
                video.setAttribute('data-autoplayed', 'true');
            }
        });
    }

    // Initial run
    autoplayVideos();

    // MutationObserver for dynamic content
    const observer = new MutationObserver(() => {
        autoplayVideos();
    });

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

    // Optional: rerun every few seconds in case of missed mutations
    setInterval(autoplayVideos, 3000);
})();