Enhanced Video Player

Comprehensive enhancement for web video players, including automatic high-quality selection, online/offline detection, and more.

// ==UserScript==
// @name         Enhanced Video Player
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Comprehensive enhancement for web video players, including automatic high-quality selection, online/offline detection, and more.
// @author       YourName
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==
(function() {
    'use strict';
    // Function to switch video quality
    function switchVideoQuality(videoElement, qualityPath) {
        const sources = videoElement.querySelectorAll('source');
        sources.forEach(function(source) {
            source.src = qualityPath;
            videoElement.load();
        });
    }
    // Enhance the video player with additional controls and functionalities
    function enhanceVideoPlayer() {
        const videos = document.querySelectorAll('video');
        videos.forEach(function(video) {
            // Quality selection logic (auto-select highest quality)
            const sources = video.querySelectorAll('source');
            if (sources.length > 0) {
                const currentPath = sources[0].src;
                const qualityPaths = {
                    '360p': currentPath.replace(/(\d+p)\.mp4$/, '360p.mp4'),
                    '480p': currentPath.replace(/(\d+p)\.mp4$/, '480p.mp4'),
                    '720p': currentPath.replace(/(\d+p)\.mp4$/, '720p.mp4'),
                    '1080p': currentPath.replace(/(\d+p)\.mp4$/, '1080p.mp4'),
                    '1440p': currentPath.replace(/(\d+p)\.mp4$/, '1440p.mp4'),
                    '2160p': currentPath.replace(/(\d+p)\.mp4$/, '2160p.mp4') // Added 4K option
                };
                // Auto-select the highest quality available
                let highestQualityPath = null;
                let highestQualityOrder = -1;
                for (const quality in qualityPaths) {
                    const order = ['360p', '480p', '720p', '1080p', '2160p'].indexOf(quality);
                    if (order > highestQualityOrder) {
                        highestQualityOrder = order;
                        highestQualityPath = qualityPaths[quality];
                    }
                }
                if (highestQualityPath) {
                    switchVideoQuality(video, highestQualityPath);
                }
            }
            // Error handling
            video.onerror = function(event) {
                console.error('Video error:', event);
                // Optionally show error message or try another source
            };
        });
        // Online/Offline detection
        window.addEventListener('online', function() {
            console.log('You are online');
        });
        window.addEventListener('offline', function() {
            console.log('You are offline');
        });
    }
    // Run the enhancement function when the script loads
    enhanceVideoPlayer();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址