user2025 / Rugplay Coinflip Watcher

// ==UserScript==
// @name         Rugplay Coinflip Watcher
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Get your gambling results faster in Rugplay so you don't have to wait that extra second to see your balance. 🎲
// @author       Houloude9
// @licence      MIT
// @match        https://rugplay.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Create toast container and styles
    function setupToastUI() {
        const style = document.createElement('style');
        style.textContent = `
        #tm-toasts {
            position: fixed;
            top: 1rem;
            right: 1rem;
            z-index: 9999;
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
        }
        .tm-toast {
            background: #111;
            color: #fff;
            padding: 12px 16px;
            border-radius: 8px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.2);
            max-width: 300px;
            font-family: system-ui, sans-serif;
            animation: slidein 0.3s ease-out;
        }
        .tm-toast.success { border-left: 4px solid #00c853; }
        .tm-toast.error   { border-left: 4px solid #d50000; }

        @keyframes slidein {
            from { opacity: 0; transform: translateX(20px); }
            to   { opacity: 1; transform: translateX(0); }
        }
        `;
        document.head.appendChild(style);

        const toastContainer = document.createElement('div');
        toastContainer.id = 'tm-toasts';
        document.body.appendChild(toastContainer);
    }

    // Display a toast
    function showToast(type, title, message) {
        const container = document.getElementById('tm-toasts');
        if (!container) return;

        const toast = document.createElement('div');
        toast.className = `tm-toast ${type}`;
        toast.innerHTML = `<strong>${title}</strong><br><small>${message}</small>`;
        container.appendChild(toast);

        setTimeout(() => toast.remove(), 4000);
    }

    // Coinflip response handler
    function handleCoinflip(data) {
        window.lastCoinflipResult = data;

        if (data.won) {
            showToast('success', '🤑 You won!', `+$${data.payout.toFixed(2)} — New Balance: $${data.newBalance.toFixed(2)}`);
        } else {
            showToast('error', '💸 You lost.', `It landed on ${data.result}. You wagered $${data.amountWagered.toFixed(2)}`);
        }
    }

    // Intercept fetch and listen for coinflip results
    const originalFetch = window.fetch;
    window.fetch = async (...args) => {
        const [url] = args;
        const response = await originalFetch(...args);

        if (url.includes('coinflip')) {
            try {
                const clone = response.clone();
                clone.json().then(data => {
                    console.log('[🎲 Coinflip]', data);
                    handleCoinflip(data);
                });
            } catch (err) {
                console.error('Failed to parse coinflip response:', err);
            }
        }

        return response;
    };

    // Init on page load
    window.addEventListener('load', () => {
        setupToastUI();

        console.log('📦 Global functions on rugplay.com:');
        for (const key in window) {
            try {
                const fn = window[key];
                if (typeof fn === 'function') {
                    console.log(`🧩 ${key}(${fn.length} arg${fn.length === 1 ? '' : 's'})`);
                }
            } catch (err) {
                console.warn(`Can't access ${key}:`, err);
            }
        }

        setTimeout(() => {
            showToast('success', '✅ Ready to gamble! Give it all.', 'QuickRes loaded.');
        }, 2500);
    });

})();