Ultimate Video & Image Quality Enhancer (No Lag, Best Previews)

Forces the highest quality playback for videos and images on all sites. Enhances thumbnails and video previews instantly without lag, pausing, or freezing.

目前為 2025-03-29 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Ultimate Video & Image Quality Enhancer (No Lag, Best Previews)
// @namespace    https://github.com/yuhaofe
// @version      1.3
// @description  Forces the highest quality playback for videos and images on all sites. Enhances thumbnails and video previews instantly without lag, pausing, or freezing.
// @author       tae
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    console.log("✅ Ultimate Video & Image Quality Enhancer is now active!");

    function enhanceMedia() {
        document.querySelectorAll('img:not([data-enhanced])').forEach(img => {
            if (!img.closest('iframe') && !img.closest('[class*="ad"], [id*="ad"]')) {
                enhanceImage(img);
            }
        });

        document.querySelectorAll('video:not([data-enhanced])').forEach(video => {
            enhanceVideo(video);
        });
    }

    function enhanceImage(img) {
        if (!img.src || img.hasAttribute('data-enhanced')) return;

        try {
            // Ensure full-resolution thumbnails
            if (img.src.includes("=s") || img.src.includes("w=") || img.src.includes("h=")) {
                img.src = img.src.replace(/=s\d+/g, '=s4096').replace(/w=\d+/g, 'w=4096').replace(/h=\d+/g, 'h=4096');
            }
            img.style.imageRendering = 'crisp-edges'; // Prioritizes high clarity
            img.style.filter = "none"; // Removes blurriness
            img.setAttribute('data-enhanced', 'true');
        } catch (e) {
            console.error('❌ Failed to enhance image:', e);
        }
    }

    function enhanceVideo(video) {
        if (video.hasAttribute('data-enhanced')) return;

        video.setAttribute('data-enhanced', 'true');
        video.preload = 'auto';
        video.playsInline = true;
        video.autobuffer = true;
        video.style.filter = "none"; // Removes any compression blur

        // Force highest available video quality
        let qualityLevels = video.getAvailableQualityLevels?.();
        if (qualityLevels && qualityLevels.length > 0) {
            let highestQuality = qualityLevels[0];
            video.setPlaybackQuality?.(highestQuality);
        }

        video.load();
    }

    // Observe the page for dynamically loaded media
    const observer = new MutationObserver(() => {
        requestAnimationFrame(() => enhanceMedia());
    });

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

    setInterval(() => enhanceMedia(), 5000);

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', enhanceMedia);
    } else {
        enhanceMedia();
    }
})();

QingJ © 2025

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