Refrag Auto Join Server

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

})();