Greasy Fork

Greasy Fork is available in English.

视频进度条拉到尾端

操作视频进度条,将其移动到最后,用于绕过基于视频进度的限制。

当前为 2024-08-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         视频进度条拉到尾端
// @namespace    none
// @version      1.1
// @description  操作视频进度条,将其移动到最后,用于绕过基于视频进度的限制。
// @author       AMin
// @match        *://*/*
// @grant        none
// @license      Proprietary
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    function manipulateProgressBar() {
        const videoElement = document.querySelector("video");

        if (videoElement) {
            const currentPos = videoElement.currentTime;
            videoElement.currentTime = videoElement.duration - 2;

            setTimeout(() => {
                videoElement.currentTime = currentPos;
            }, 900);
        }
    }

    function createButton() {
        const triggerButton = document.createElement('button');
        triggerButton.textContent = '视频置为最后';
        Object.assign(triggerButton.style, {
            position: 'absolute',
            top: '10px',
            left: '10px',
            backgroundColor: '#444',
            color: '#fff',
            border: 'none',
            padding: '8px 16px',
            cursor: 'pointer',
            opacity: '0.85',
            zIndex: '10000'
        });

        triggerButton.addEventListener('click', manipulateProgressBar);
        document.body.appendChild(triggerButton);
    }

    function checkForVideoAndCreateButton() {
        if (document.querySelector("video")) {
            createButton();
        } else {
            // Check periodically if the video element appears later
            const observer = new MutationObserver((mutations) => {
                for (let mutation of mutations) {
                    if (mutation.addedNodes.length) {
                        for (let node of mutation.addedNodes) {
                            if (node.tagName === 'VIDEO' || node.querySelector('video')) {
                                createButton();
                                observer.disconnect();
                                return;
                            }
                        }
                    }
                }
            });

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

    checkForVideoAndCreateButton();
})();