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.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Ultimate Video & Image Quality Enhancer (No Lag, Best Previews)
// @namespace    https://greasyfork.org/shannonturner
// @version      1.4
// @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() {
        try {
            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);
            });
        } catch (err) {
            console.warn("❌ Error while enhancing media:", err);
        }
    }

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

        try {
            // Upgrade to high-resolution if typical low-res parameters are detected
            img.src = img.src
                .replace(/=s\d+/g, '=s2160')
                .replace(/w=\d+/g, 'w=2160')
                .replace(/h=\d+/g, 'h=3840');

            img.style.imageRendering = 'crisp-edges';
            img.style.filter = 'none';
            img.setAttribute('data-enhanced', 'true');
        } catch (e) {
            console.error('❌ Failed to enhance image:', e);
        }
    }

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

        try {
            video.setAttribute('data-enhanced', 'true');
            video.preload = 'auto';
            video.playsInline = true;
            video.autobuffer = true;
            video.style.filter = 'none';

            // Attempt to force highest quality playback
            if (typeof video.getAvailableQualityLevels === 'function') {
                const levels = video.getAvailableQualityLevels();
                if (levels?.length) {
                    video.setPlaybackQuality?.(levels[0]);
                }
            }

            video.load();
        } catch (e) {
            console.error('❌ Failed to enhance video:', e);
        }
    }

    function observeDOM() {
        const observer = new MutationObserver(() => {
            requestAnimationFrame(enhanceMedia);
        });

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

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

    setInterval(enhanceMedia, 7000);
})();