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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();