BetterDiscordApp-v2/core/src/sparkplug.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-01-12 02:06:43 +01:00
(() => {
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, protocols);
}
hook(url, protocols) {
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-02-15 18:00:21 +01:00
2018-01-12 02:06:43 +01:00
}
2018-01-12 07:31:02 +01:00
window.WebSocket = WSHook;
2018-02-15 18:00:21 +01:00
})();