-
Notifications
You must be signed in to change notification settings - Fork 4
/
inject.js
executable file
·31 lines (28 loc) · 900 Bytes
/
inject.js
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
(function(){
'use strict';
const inject = function () {
// Necessary because extensions cannot directly access the page's global variables.
const scr = document.createElement('script');
const swapWebSocketImplStr = swapWebSocketImpl.toString();
scr.textContent = '(function() {' +
swapWebSocketImplStr +
' swapWebSocketImpl();' +
'})();';
(document.head || document.documentElement).appendChild(scr);
scr.parentNode.removeChild(scr);
};
inject();
function swapWebSocketImpl() {
const send = window.WebSocket.prototype.send;
window.WebSocket.prototype.send = function () {
const args = [].slice.call(arguments, 0);
try {
const parsed = JSON.parse(args[0] || '{}');
if (parsed.type === 'user_typing') {
return;
}
} catch(ex) {}
return send.apply(this, args);
};
}
})();