-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscript.user.js
More file actions
71 lines (53 loc) · 1.62 KB
/
script.user.js
File metadata and controls
71 lines (53 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// ==UserScript==
// @name WebSocket Data Viewer
// @namespace https://github.com/Lemons1337/WebSocket-Data-Viewer
// @version 0.1.2
// @description try to take over the world!
// @author Lemons
// @match *://*/*
// @run-at document-start
// @require https://cdnjs.cloudflare.com/ajax/libs/msgpack-lite/0.1.26/msgpack.min.js
// @grant none
// ==/UserScript==
window.msgpack = msgpack;
window.wsData = {};
function parseData(data) {
if (data instanceof DataView) {
data = new Uint8Array(data.buffer);
} else if (data instanceof ArrayBuffer) {
data = new Uint8Array(data);
} else {
try {
data = JSON.parse(data);
} catch (err) {}
}
try {
data = msgpack.decode(data);
} catch (err) {}
return data;
}
window.WebSocket = new Proxy(WebSocket, {
construct(target, args) {
var ws = window.wsHook = new target(...args);
var domain = new URL(ws.url).origin;
window.wsData[domain] = {
received: [],
sent: []
};
var send = ws.send;
ws.send = function(data) {
var ret = send.apply(this, arguments);
data = parseData(data);
window.wsData[domain].sent.push(data);
console.log('Outgoing ->', data);
return ret;
}
ws.addEventListener('message', function(message) {
var data = message.data;
data = parseData(data);
window.wsData[domain].received.push(data);
console.log('Incoming ->', data);
});
return ws;
}
});