Refrag Auto Join Server

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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

})();