Glar.io Websocket Decoder

You can decode messages from WebSocket Server by the Hooks.Protocol.decode or window.SocketProtocol.decode

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         Glar.io Websocket Decoder
// @name:ru      Декодировщик WebSocket-сообщений в Glar.io
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  You can decode messages from WebSocket Server by the Hooks.Protocol.decode or window.SocketProtocol.decode
// @description:ru   Вы можете декодировать сообщения от WebSocket-сервера обращаясь к Hooks.Protocol.decode или window.SocketProtocol.decode
// @author       Dekudo#1414
// @match        *://glar.io/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-start
// ==/UserScript==

(() => {
  class Utils {
    static createHook(target, property, callback) {
      const symbol = Symbol(property);

      Object.defineProperty(target, property, {
        get() {
          return this[symbol];
        },

        set(value) {
          this[symbol] = value;

          callback(this, symbol);
        }
      })
    }
  }

  Utils.createHook(Object.prototype, "Protocol", (_this, _symbol) => {
    Reflect.set(window, "SocketProtocol", _this[_symbol]);
  })

  window.WebSocket = new Proxy(WebSocket, {
    construct(Target, args) {
      const socket = new Target(...args);

      socket.addEventListener("message", message => {
        const data = new Uint8Array(message.data);

        console.log(window.SocketProtocol.decode(data));
      })

      return socket;
    }
  })
})();