2018-01-12 02:06:43 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
(() => {
|
|
|
|
if (window.__bd && window.__bd.ignited) return;
|
|
|
|
|
|
|
|
console.log('[BetterDiscord|Sparkplug]');
|
|
|
|
|
|
|
|
const ls = window.localStorage;
|
|
|
|
if (!ls) console.warn('[BetterDiscord|Sparkplug] Failed to hook localStorage :(');
|
|
|
|
const wsOrig = window.WebSocket;
|
|
|
|
|
|
|
|
window.__bd = {
|
|
|
|
localStorage: ls,
|
|
|
|
wsHook: null,
|
|
|
|
wsOrig,
|
|
|
|
ignited: true
|
|
|
|
};
|
|
|
|
|
2018-01-12 07:31:02 +01:00
|
|
|
class WSHook extends window.WebSocket {
|
|
|
|
|
|
|
|
constructor(url, protocols) {
|
|
|
|
super(url, protocols);
|
|
|
|
this.hook(url);
|
|
|
|
console.log("IS IT RUNNING ASYNC?");
|
|
|
|
}
|
|
|
|
|
|
|
|
hook(url) {
|
|
|
|
console.info(`[BetterDiscord|WebSocket Proxy] new WebSocket detected, url: ${url}`);
|
|
|
|
if (!url.includes('gateway.discord.gg')) return;
|
|
|
|
|
|
|
|
if (window.__bd.setWS) {
|
|
|
|
window.__bd.setWS(this);
|
|
|
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket sent to instance`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-12 02:06:43 +01:00
|
|
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to __bd['wsHook']`);
|
2018-01-12 07:31:02 +01:00
|
|
|
window.__bd.wsHook = this;
|
2018-01-12 02:06:43 +01:00
|
|
|
}
|
|
|
|
|
2018-01-12 07:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
window.WebSocket = WSHook;
|
2018-01-12 02:06:43 +01:00
|
|
|
})();
|