Rickroll and Click.ly Blocker

Block Rickroll links, Click.ly links, and the specific YouTube video link

目前為 2024-08-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Rickroll and Click.ly Blocker
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Block Rickroll links, Click.ly links, and the specific YouTube video link
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // URL patterns to identify Rickroll links, Click.ly links, and the specific YouTube link
    const blockPatterns = [
        /rickroll/i,
        /nevergonnagiveyouup/i,
        /click\.ly/i,
        /youtube\.com\/watch\?v=dQw4w9WgXcQ/i // Specific YouTube Rickroll video link
    ];

    // Function to block specified links
    function blockLinks() {
        // Find all anchor tags on the page
        const links = document.querySelectorAll('a');
        
        links.forEach(link => {
            if (blockPatterns.some(pattern => pattern.test(link.href))) {
                // Block the link
                link.style.display = 'none'; // Hide the link
                // Optionally, you can replace the link text
                // link.textContent = '[Link blocked]';
            }
        });
    }

    // Run the function initially
    blockLinks();

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

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

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