以下是一个 Tampermonkey 脚本的示例代码,可实现在观看 YouTube 视频时自动从第 30 秒开始,并跳过结尾前的 120 秒。

// ==UserScript==
// @name         YouTube Auto Skip
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically skip to 30 seconds and skip the last 120 seconds on YouTube videos.
// @author       Your Name
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Wait for the YouTube player to be ready
    var waitForPlayer = setInterval(function() {
        var player = document.getElementById('movie_player');
        if (player && player.getPlayerState) {
            clearInterval(waitForPlayer);

            // Skip to 30 seconds when the video starts playing
            player.addEventListener('onStateChange', function(event) {
                if (event.data === YT.PlayerState.PLAYING) {
                    player.seekTo(30, true);
                }
            });

            // Skip the last 120 seconds when the video ends
            player.addEventListener('onStateChange', function(event) {
                if (event.data === YT.PlayerState.ENDED) {
                    player.seekTo(player.getDuration() - 120, true);
                }
            });
        }
    }, 1000);
})();

请注意,这个脚本假设你已经安装了 Tampermonkey 浏览器插件。


原文地址: https://www.cveoy.top/t/topic/qnPz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录