Block Official Rickroll Video

Block any content related to the official Rickroll YouTube video while allowing other content

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Block Official Rickroll Video
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Block any content related to the official Rickroll YouTube video while allowing other content
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // URL of the specific Rickroll video to block
    const rickrollUrl = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';

    // Function to block content related to the Rickroll video
    function blockRickrollContent() {
        // Find all anchor tags on the page
        const links = document.querySelectorAll('a');
        
        links.forEach(link => {
            if (link.href.includes(rickrollUrl)) {
                // Block the Rickroll video link
                link.style.display = 'none'; // Hide the link
                // Optionally, you can replace the link text
                // link.textContent = '[Link blocked]';
            }
        });

        // Find all iframes on the page
        const iframes = document.querySelectorAll('iframe');

        iframes.forEach(iframe => {
            if (iframe.src.includes(rickrollUrl)) {
                // Block the iframe containing the Rickroll video
                iframe.style.display = 'none'; // Hide the iframe
                // Optionally, you can replace the iframe content
                // iframe.src = 'about:blank'; // Clear the iframe source
            }
        });
    }

    // Run the function initially
    blockRickrollContent();

    // Observe changes to dynamically loaded content
    const observer = new MutationObserver(() => {
        blockRickrollContent();
    });

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

    // Handle links and iframes added to the DOM after script execution
    document.addEventListener('DOMContentLoaded', () => {
        blockRickrollContent();
    });
})();