ChessCom Variants: Private arrows

Prevent your arrows from being shared with spectators

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         ChessCom Variants: Private arrows
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Prevent your arrows from being shared with spectators
// @author       CzEclipsia discord@cz_eclipsia
// @match        *://*.chess.com/variants*
// @icon         https://www.chess.com/favicon.ico
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const TARGET = "wss://variants.gcp-prod.chess.com";
    const windowWebSocket = window.WebSocket;

    window.WebSocket.prototype.sendMessage = function(json) {
        const data = JSON.stringify(json);
        const event = new MessageEvent('message', {data});
        this.dispatchEvent(event);
    };

    window.WebSocket = function (url, protocols) {
        const ws = protocols
            ? new windowWebSocket(url, protocols)
            : new windowWebSocket(url);

        if (typeof url === "string" && url.startsWith(TARGET)) {
            const wsSend = ws.send;
            ws.send = function(data) {
                try {
                    const json = JSON.parse(data);
                    if (json.action == "game" && json.data.action == "draw-arrow") {
                        return ws.sendMessage({
                            mutation: "new_arrow",
                            data: json.data
                        });
                    }
                } catch {}

                wsSend.call(ws, data);
            };
        }

        return ws;
    };

    window.WebSocket.prototype = windowWebSocket.prototype;
})();