Universal Video Sharpener (CSS Filter)

Applies video sharpening using CSS filters across websites

当前为 2024-12-21 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Universal Video Sharpener (CSS Filter)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Applies video sharpening using CSS filters across websites
// @match        *://*/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Configuration
    const CONFIG = {
        contrast: 1.1,      
        brightness: 1.2,   
        saturate: 1.1,      
        debugMode: false
    };

    // Logging function
    function log(message) {
        if (CONFIG.debugMode) {
            console.log(`[Video Sharpener] ${message}`);
        }
    }

    // Detect if an element is likely a video
    function isVideoElement(element) {
        return element instanceof HTMLVideoElement &&
               element.videoWidth > 0 &&
               element.videoHeight > 0 &&
               !element.paused;
    }

    // Apply CSS sharpness filter
    function applySharpnessFilter(video, isEnabled) {
        if (!video) return;

        try {
            if (isEnabled) {
                const { contrast, brightness, saturate } = CONFIG;
                video.style.filter = `
                    contrast(${contrast})
                    brightness(${brightness})
                    saturate(${saturate})
                `;
                video.dataset.sharpened = 'true';
                log('CSS Sharpness filter applied');
            } else {
                video.style.filter = 'none';
                delete video.dataset.sharpened;
                log('Sharpness filter removed');
            }
        } catch (error) {
            console.error('Error applying sharpness filter:', error);
        }
    }

    // Main processing function
    function processVideos() {
        const isScriptEnabled = GM_getValue('universalSharpenerEnabled', false);
        if (!isScriptEnabled) return;

        const videos = document.querySelectorAll('video:not([data-sharpened])');
        videos.forEach(video => {
            if (isVideoElement(video)) {
                applySharpnessFilter(video, true);
            }
        });
    }

   
    function initScript() {
        // Global toggle menu command
        GM_registerMenuCommand('Toggle Video Sharpener', () => {
            const currentState = GM_getValue('universalSharpenerEnabled', false);
            GM_setValue('universalSharpenerEnabled', !currentState);
            location.reload();
        });

        // Use MutationObserver for dynamic content
        const observer = new MutationObserver(() => {
            processVideos();
        });

        // Observe the entire document for changes
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        
        processVideos();
        setInterval(processVideos, 3000);
    }

    
    initScript();
})();