Block Multiple Casino Game Links

Blocks multiple specified game links and shows an alert.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Block Multiple Casino Game Links
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Blocks multiple specified game links and shows an alert.
// @author       You
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Array of the game links to block
    const blockedGames = [
        "/casino/games/dice",
        "/casino/games/plinko",
        "/casino/games/primedice",
        "/casino/games/crash",
        "/casino/games/pump",
        "/casino/games/cases",
        "/casino/games/mines",
        "/casino/games/limbo",
        "/casino/games/packs",
        "/casino/games/keno",
        "/casino/games/Hilo"
    ];

    // Function to find and block the game links
    function blockGameLinks() {
        // Loop through each game path in our block list
        blockedGames.forEach(function(gameHref) {
            // Find all links that match the current game path and haven't been processed yet
            const gameLinks = document.querySelectorAll(`a[href="${gameHref}"]:not([data-blocked])`);

            // Attach the click-blocking event to each found link
            gameLinks.forEach(function(link) {
                // Prevent the link from being followed
                link.addEventListener('click', function(event) {
                    event.preventDefault();
                    event.stopPropagation(); // Stop the event from bubbling up further
                    alert("This game is blocked.");
                });

                // Mark this link as processed so we don't attach another listener
                link.setAttribute('data-blocked', 'true');
            });
        });
    }

    // --- Main Execution ---

    // Run the function once on initial page load
    blockGameLinks();

    // Set up a MutationObserver to watch for new content being added to the page
    // This is important for modern websites that load content dynamically
    const observer = new MutationObserver(function(mutations) {
        // If nodes were added, re-run our blocking function to check for new links
        if (mutations.some(mutation => mutation.addedNodes.length > 0)) {
            blockGameLinks();
        }
    });

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