Scenexe ignorer

adds the /ignore playerID and /unignore playerID commands to scenexe.

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     Scenexe ignorer
// @namespace   scenexeignorer
// @description adds the /ignore playerID and /unignore playerID commands to scenexe.
// @author    discordtehe
// @license  MIT
// @version  1.0.1
// @grant    none
// @match     https://scenexe.io
// @match     https://test.scenexe.io
// @match     https://new-test.scenexe.io
// @match     https://test2.scenexe.io
// @require   https://greatest.deepsurf.us/scripts/457386-scenexeutils/code/ScenexeUtils.js?version=1133496
// @run-at   document-start
// ==/UserScript==

window.actionIgnore = function(action, playerID) {
    var data = JSON.parse(localStorage.getItem('ignored') || '{}');
    if (action == 'add') {
        data[playerID] = true;
        localStorage.setItem('ignored', JSON.stringify(data));
    } else if (action == 'remove') {
        delete data[playerID];
        localStorage.setItem('ignored', JSON.stringify(data));
    } else if (action == 'get') {
        return data;
    }
}

window.modifyEvents = function(events) {
    const newEvents = [];
    for (var i = 0; i < events.length; i++) {
      var type = events[i][0];
      var content = events[i][1];
      var ignored = actionIgnore('get');
      if (type == 1) {
          if (content.id in ignored)
              continue;
      } else if (type == 12) {
          if (content[0] in ignored)
              continue;
      }
      newEvents.push(events[i]);
    }
    return newEvents;
}

WebSocket.prototype.addEventListener = new Proxy(WebSocket.prototype.addEventListener, {
    apply: function (target, scope, args) {
        if (args[0] === 'message') {
            args[1] = new Proxy(args[1], {
                apply: function(ftarget, fscope, fargs) {
                    var decoded = decode(new Uint8Array(fargs[0].data));
                    if (decoded[0] == 0)
                        decoded[1][10] = modifyEvents(decoded[1][10]);
                    fargs[0] = new MessageEvent('message', {data: encode(decoded)})
                    let fdata = ftarget.apply(fscope, fargs);
                    return fdata;
                }
            })
        }
        let data = target.apply(scope, args);
        return data;
    }
})

WebSocket.prototype.send = new Proxy(WebSocket.prototype.send, {
    apply: function (target, scope, args) {
        var packet = decode(new Uint8Array(args[0]));
        if (packet[0] == 4 && typeof packet[1] == 'string') {
            var temp = packet[1].split(' ');
            if (temp.length > 1 && temp[0] == '/ignore')
                actionIgnore('add', temp[1]);
            else if (temp.length > 1 && temp[0] == '/unignore')
                actionIgnore('remove', temp[1]);
        }
        let data = target.apply(scope, args);
        return data;
    }
})