Torn: Block 1m & 10m Slots Bets

Blocks the 1,000,000 and 10,000,000 bet buttons on the Torn slots page.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torn: Block 1m & 10m Slots Bets
// @namespace    whiskey_jack.torn 
// @version      1.0
// @description  Blocks the 1,000,000 and 10,000,000 bet buttons on the Torn slots page.
// @author       Whiskey_Jack [1994581]
// @match        https://www.torn.com/page.php?sid=slots*
// @match        https://www.torn.com/loader.php?sid=slots*
// @run-at       document-start
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict';

    const LOG_PREFIX = '[SlotsBlocker]';

    // Style: visually dim + make unclickable
    const STYLE = `
        .betbtn.btn-1m,
        .betbtn.btn-10m {
            pointer-events: none !important;
            opacity: 0.4 !important;
            cursor: not-allowed !important;
            filter: grayscale(1);
        }
    `;

    function injectStyle() {
        try {
            if (typeof GM_addStyle !== 'undefined') {
                GM_addStyle(STYLE);
            } else {
                const style = document.createElement('style');
                style.textContent = STYLE;
                document.head.appendChild(style);
            }
            console.log(LOG_PREFIX, 'CSS injected – 1m & 10m buttons visually disabled.');
        } catch (e) {
            console.warn(LOG_PREFIX, 'Failed to inject CSS:', e);
        }
    }

    function blockButtons(root = document) {
        const buttons = root.querySelectorAll('.betbtn.btn-1m, .betbtn.btn-10m');
        if (!buttons.length) return;

        buttons.forEach(btn => {
            // Prevent duplicate handlers
            if (btn.dataset.slotsBlockerAttached === '1') return;

            btn.dataset.slotsBlockerAttached = '1';
            btn.setAttribute('title', 'Blocked by userscript');

            btn.addEventListener('click', (e) => {
                e.stopImmediatePropagation();
                e.stopPropagation();
                e.preventDefault();
                console.log(LOG_PREFIX, 'Blocked click on', btn.className, 'data-bet=', btn.getAttribute('data-bet'));
            }, true);
        });
    }

    function setupObserver() {
        if (!document.body) {
            // Fallback: wait until body exists
            const interval = setInterval(() => {
                if (document.body) {
                    clearInterval(interval);
                    setupObserver();
                }
            }, 50);
            return;
        }

        // Initial pass
        blockButtons(document);

        const observer = new MutationObserver(mutations => {
            for (const m of mutations) {
                if (!m.addedNodes || !m.addedNodes.length) continue;
                m.addedNodes.forEach(node => {
                    if (node.nodeType !== 1) return; // ELEMENT_NODE
                    if (node.matches && (node.matches('.betbtn.btn-1m, .betbtn.btn-10m'))) {
                        blockButtons(node.parentNode || node);
                    } else if (node.querySelector) {
                        blockButtons(node);
                    }
                });
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
        console.log(LOG_PREFIX, 'MutationObserver attached.');
    }

    // Run ASAP
    injectStyle();

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', () => {
            setupObserver();
        });
    } else {
        setupObserver();
    }
})();