GB Server Connection Display

Display the GoBattle server when connected with WS | Join us! - https://discord.gg/3xDbJ8QD8f

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.

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

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         GB Server Connection Display
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Display the GoBattle server when connected with WS | Join us! - https://discord.gg/3xDbJ8QD8f
// @author       GoBattle Hacks Official
// @match        *://gobattle.io/*
// @match        *://*.gobattle.io/*
// @run-at       document-start
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  const OriginalWS = window.WebSocket;

  const SERVER_NAMES = {
    'wss://france2.gobattle.io:10116/': 'France',
    'wss://us-west.gobattle.io:10116/': 'USA West',
    'wss://singapore2.gobattle.io:10116/': 'Singapore',
  };

  function getServerName(url) {
    if (url.endsWith('/')) url = url.slice(0, -1);
    return SERVER_NAMES[url + '/'] || url;
  }

  function showServerNotice(name) {
    const notice = document.createElement('div');
    notice.textContent = `Connected to: ${name}`;
    Object.assign(notice.style, {
      position: 'fixed',
      bottom: '20px',
      right: '20px',
      background: 'rgba(0,0,0,0.7)',
      color: 'yellow',
      padding: '10px 15px',
      borderRadius: '8px',
      fontSize: '16px',
      fontWeight: 'bold',
      zIndex: 999999,
      opacity: '1',
      transition: 'opacity 1s ease-out',
    });
    document.body.appendChild(notice);

    setTimeout(() => {
      notice.style.opacity = '0';
      setTimeout(() => notice.remove(), 1000);
    }, 5000);
  }

  const WSProxy = new Proxy(OriginalWS, {
    construct(target, args, newTarget) {
      const ws = Reflect.construct(target, args, newTarget);

      ws.addEventListener("open", () => {
        const serverName = getServerName(ws.url);
        showServerNotice(serverName);
      });

      return ws;
    },
    apply(target, thisArg, args) {
      return new target(...args);
    }
  });

  window.WebSocket = WSProxy;
})();