YouTube Mobile 144p (5-Second Force)

Forces 144p for the first 5 seconds of a video, then stops to allow manual changes.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Mobile 144p (5-Second Force)
// @namespace    http://tampermonkey.net/
// @version      4.0
// @description  Forces 144p for the first 5 seconds of a video, then stops to allow manual changes.
// @author       Gemini
// @match        *://m.youtube.com/*
// @grant        none
// @run-at       document-idle
// @license   MIT
// ==/UserScript==

(function() {
    'use strict';

    let currentVideoId = "";
    let enforcementStartTime = 0;
    const ENFORCE_DURATION = 5000; // Force quality for 5 seconds

    function getVideoId() {
        const params = new URLSearchParams(window.location.search);
        return params.get('v') || (window.location.pathname.includes('/shorts/') ? window.location.pathname : null);
    }

    function enforceQuality() {
        const newVideoId = getVideoId();

        // 1. Detect if it's a new video
        if (newVideoId && newVideoId !== currentVideoId) {
            currentVideoId = newVideoId;
            enforcementStartTime = Date.now(); // Start the 5-second timer
            console.log("New video detected. Enforcing 144p for 5 seconds...");
        }

        // 2. If we are within the 5-second window, FORCE 144p
        if (Date.now() - enforcementStartTime < ENFORCE_DURATION) {
            const player = document.getElementById('movie_player') || document.querySelector('.html5-video-player');

            if (player && typeof player.setPlaybackQuality === 'function') {
                // Try to set 'tiny' (144p)
                const currentQ = player.getPlaybackQuality();
                if (currentQ !== 'tiny') {
                    player.setPlaybackQuality('tiny');
                }

                // Also try setPlaybackQualityRange (often needed for mobile)
                if (typeof player.setPlaybackQualityRange === 'function') {
                    player.setPlaybackQualityRange('tiny', 'tiny');
                }
            }
        }
    }

    // Run heavily to catch the load moment
    setInterval(enforceQuality, 500);
})();