Blur YouTube Videos with Shortcut

Apply a 100px blur effect to YouTube videos with Alt+Y

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Blur YouTube Videos with Shortcut
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Apply a 100px blur effect to YouTube videos with Alt+Y
// @author       Drewby123
// @match        *://www.youtube.com/*
// @license      MIT    
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let isBlurred = false; // Track the blur state

    // Function to toggle the blur effect
    function toggleBlur() {
        const videos = document.querySelectorAll('video');
        isBlurred = !isBlurred;
        const blurValue = isBlurred ? 'blur(100px)' : 'none'; // Toggle blur
        videos.forEach(video => {
            video.style.filter = blurValue;
            video.style.transition = 'filter 0.5s'; // Smooth transition
        });
    }

    // Event listener for Alt+Y
    document.addEventListener('keydown', event => {
        if (event.altKey && event.key.toLowerCase() === 'y') {
            toggleBlur();
        }
    });

    // Apply blur to dynamically loaded videos
    const observer = new MutationObserver(() => {
        if (isBlurred) {
            const videos = document.querySelectorAll('video');
            videos.forEach(video => {
                video.style.filter = 'blur(100px)';
                video.style.transition = 'filter 0.5s';
            });
        }
    });

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