Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This shows that Lichess's frontend discards illegal moves. Run this script in Tampermonkey and set a breakpoint to the '// outcoming websockets' line. Try to make an illegal move. The line won't be reached, because Lichess discards illegal moves. Try to make a legal move, and the line will be reached.
- // ==UserScript==
- // @name Check WebSockets
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @match https://lichess.org/*
- // @icon https://www.google.com/s2/favicons?domain=lichess.org
- // @grant none
- // @run-at document-start
- // ==/UserScript==
- console.log('script to check websockets');
- (function () {
- //to get the move that has been sent by the client, https://stackoverflow.com/a/31182643/10364842
- var OrigWebSocket = window.WebSocket;
- var callWebSocket = OrigWebSocket.apply.bind(OrigWebSocket);
- var wsAddListener = OrigWebSocket.prototype.addEventListener;
- wsAddListener = wsAddListener.call.bind(wsAddListener);
- window.WebSocket = function WebSocket(url, protocols) {
- var ws;
- if (!(this instanceof WebSocket)) {
- // Called without 'new' (browsers will throw an error).
- ws = callWebSocket(this, arguments);
- } else if (arguments.length === 1) {
- ws = new OrigWebSocket(url);
- } else if (arguments.length >= 2) {
- ws = new OrigWebSocket(url, protocols);
- } else {
- // No arguments (browsers will throw an error)
- ws = new OrigWebSocket();
- }
- wsAddListener(ws, 'message', function (event) {
- // TODO: Do something with event.data (received data) if you wish.
- console.log(event)
- });
- return ws;
- }.bind();
- window.WebSocket.prototype = OrigWebSocket.prototype;
- window.WebSocket.prototype.constructor = window.WebSocket;
- var wsSend = OrigWebSocket.prototype.send;
- wsSend = wsSend.apply.bind(wsSend);
- OrigWebSocket.prototype.send = function (data) {
- // TODO: Do something with the sent data if you wish.
- if (data !== null && data !== 'null') {
- // outcoming websockets
- console.log(data);
- debugger;
- }
- return wsSend(this, arguments);
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement