2018-03-20 22:11:11 +01:00
|
|
|
/**
|
|
|
|
* BetterDiscord Sparkplug
|
|
|
|
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
|
|
|
|
* All rights reserved.
|
|
|
|
* https://github.com/JsSucks - https://betterdiscord.net
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
* This file is evaluated in the renderer process!
|
|
|
|
*/
|
|
|
|
|
2018-05-28 02:42:59 +02:00
|
|
|
import electron, { ipcRenderer } from 'electron';
|
|
|
|
|
2018-01-12 02:06:43 +01:00
|
|
|
(() => {
|
2018-03-20 22:11:11 +01:00
|
|
|
if (module.exports.bd) return;
|
2018-01-12 02:06:43 +01:00
|
|
|
|
|
|
|
console.log('[BetterDiscord|Sparkplug]');
|
|
|
|
|
2018-05-28 02:42:59 +02:00
|
|
|
const currentWindow = electron.remote.getCurrentWindow();
|
|
|
|
|
|
|
|
if (currentWindow.__bd_preload) {
|
|
|
|
for (let preloadScript of currentWindow.__bd_preload) {
|
|
|
|
try {
|
|
|
|
require(preloadScript);
|
|
|
|
} catch (err) {
|
|
|
|
console.error('[BetterDiscord|Sparkplug] Error thrown in preload script', preloadScript, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcRenderer.on('--bd-inject-script', (event, {script, variable}) => {
|
|
|
|
console.log('[BetterDiscord|Sparkplug] Injecting script', script, variable);
|
|
|
|
if (variable) window[variable] = require(script);
|
|
|
|
else require(script);
|
|
|
|
});
|
|
|
|
|
2018-01-12 02:06:43 +01:00
|
|
|
const ls = window.localStorage;
|
|
|
|
if (!ls) console.warn('[BetterDiscord|Sparkplug] Failed to hook localStorage :(');
|
|
|
|
const wsOrig = window.WebSocket;
|
|
|
|
|
2018-03-20 22:11:11 +01:00
|
|
|
const bd = module.exports.bd = {
|
2018-01-12 02:06:43 +01:00
|
|
|
localStorage: ls,
|
|
|
|
wsHook: null,
|
|
|
|
wsOrig,
|
|
|
|
ignited: true
|
2018-03-20 22:11:11 +01:00
|
|
|
};
|
2018-01-12 02:06:43 +01:00
|
|
|
|
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;
|
|
|
|
|
2018-03-20 22:11:11 +01:00
|
|
|
if (bd.setWS) {
|
|
|
|
bd.setWS(this);
|
2018-01-12 07:31:02 +01:00
|
|
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket sent to instance`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-20 22:11:11 +01:00
|
|
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to bd.wsHook`);
|
|
|
|
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
|
|
|
})();
|