Block Official Rickroll Video

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

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

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

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

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

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