Refrag Auto Join Server

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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);

})();