Refrag Auto Join Server

Automatically joins Refrag server when it starts (opens steam:// link)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Refrag Auto Join Server
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  Automatically joins Refrag server when it starts (opens steam:// link)
// @author       Claude
// @match        https://play.refrag.gg/*
// @grant        none
// @license      MIT
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    const CHECK_INTERVAL_MS = 2000;

    let joined = false;
    let statusBox;
    let intervalId;

    function createStatusBox() {
        const box = document.createElement('div');
        box.id = 'refrag-autojoin-status';
        Object.assign(box.style, {
            position:     'fixed',
            bottom:       '18px',
            right:        '18px',
            zIndex:       '99999',
            background:   '#1a1a2e',
            color:        '#e0e0e0',
            border:       '1px solid #4f46e5',
            borderRadius: '10px',
            padding:      '10px 16px',
            fontSize:     '13px',
            fontFamily:   'monospace',
            boxShadow:    '0 4px 20px rgba(79,70,229,0.4)',
            minWidth:     '240px',
            lineHeight:   '1.6',
        });
        document.body.appendChild(box);
        return box;
    }

    function setStatus(msg, color = '#a5b4fc') {
        if (!statusBox) statusBox = createStatusBox();
        statusBox.innerHTML =
            `<b style="color:#818cf8">🎮 Refrag AutoJoin</b><br>` +
            `<span style="color:${color}">${msg}</span>`;
    }

    function findSteamLink() {
        const anchor = document.querySelector('a[href^="steam://connect/"]');
        if (anchor) return anchor.href;
        return null;
    }

    function doJoin(url) {
        joined = true;
        clearInterval(intervalId);
        console.log('[Refrag AutoJoin] Opening:', url);
        setStatus(`✅ Joined!<br><small style="word-break:break-all">${url}</small>`, '#4ade80');
        window.location.href = url;
    }

    function tick() {
        if (joined) return;
        const link = findSteamLink();
        if (!link) {
            setStatus('🔴 Server offline – waiting...', '#f87171');
            return;
        }
        doJoin(link);
    }

    setStatus('⚡ Script active – monitoring...', '#a5b4fc');
    intervalId = setInterval(tick, CHECK_INTERVAL_MS);

})();