Patches ws connection to hook set-word-points rpc
// ==UserScript==
// @name Points Patch
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Patches ws connection to hook set-word-points rpc
// @author EnergoStalin
// @match https://meme-police.ru/bg/alias
// @icon https://www.google.com/s2/favicons?sz=64&domain=meme-police.ru
// @license GPL3
// @grant none
// ==/UserScript==
(function () {
'use strict';
let change = 0;
let enableOnEnd = true;
let state = null;
let onNextStateUpdate = null;
const listeners = {
'timer-end': function(ws) {
onNextStateUpdate = (state) => {
if(!enableOnEnd) return;
const words = JSON.parse(JSON.stringify(state.currentWords))
for(let i = 0; i < words.length; i++) {
words[i].points = 0;
}
sendRpc(ws, 'set-word-points', words);
};
},
'state': function(_, data) {
state = data;
if(onNextStateUpdate) {
onNextStateUpdate(data);
onNextStateUpdate = null;
}
}
}
WebSocket.prototype.send = new Proxy(WebSocket.prototype.send, {
apply: function (target, scope, args) {
if(!scope.hooked) { // Apply listeners
scope.addEventListener('message', (msg) => {
const data = JSON.parse(msg.data);
listeners[data.a[0]]?.(scope, data.a[1]);
})
scope.hooked = true;
}
return target.apply(scope, args);
}
});
const sendRpc = function(ws, method, payload) {
ws.send(JSON.stringify({ a: { 0: method, 1: payload }, c: '/bg/alias' }))
}
})();