Igniter
This commit is contained in:
parent
662329c5e9
commit
8e308f2a65
|
@ -27094,7 +27094,7 @@ module.exports = window.require("electron");
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
/* 131 */
|
/* 131 */
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
/***/ (function(module, exports) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BetterDiscord Client WebpackModules Module
|
* BetterDiscord Client WebpackModules Module
|
||||||
|
@ -27111,6 +27111,7 @@ class WebpackModules {
|
||||||
static async getModuleByProps(props) {
|
static async getModuleByProps(props) {
|
||||||
const modules = await this.getAllModules();
|
const modules = await this.getAllModules();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const rm = [];
|
||||||
for (let index in modules) {
|
for (let index in modules) {
|
||||||
if (!modules.hasOwnProperty(index)) continue;
|
if (!modules.hasOwnProperty(index)) continue;
|
||||||
const module = modules[index];
|
const module = modules[index];
|
||||||
|
@ -27118,11 +27119,11 @@ class WebpackModules {
|
||||||
|
|
||||||
if (!exports || typeof exports !== 'object') continue;
|
if (!exports || typeof exports !== 'object') continue;
|
||||||
if (!(props in exports)) continue;
|
if (!(props in exports)) continue;
|
||||||
|
rm.push(module);
|
||||||
resolve(module.exports);
|
// resolve(module);
|
||||||
break;
|
// break;
|
||||||
}
|
}
|
||||||
|
resolve(rm);
|
||||||
reject(null);
|
reject(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -27133,10 +27134,14 @@ class WebpackModules {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
for (let index in modules) {
|
for (let index in modules) {
|
||||||
if (!modules.hasOwnProperty(index)) continue;
|
if (!modules.hasOwnProperty(index)) continue;
|
||||||
if (typeof exports === 'object' && name in exports) {
|
const module = modules[index];
|
||||||
|
const { exports } = module;
|
||||||
|
if (!exports) continue;
|
||||||
|
|
||||||
|
if (typeof exports === 'object' && (name in exports || exports.name === name)) {
|
||||||
resolve(module.exports);
|
resolve(module.exports);
|
||||||
break;
|
break;
|
||||||
} else if (false) {
|
} else if (typeof exports === 'function' && exports.name === name) {
|
||||||
resolve(module.exports);
|
resolve(module.exports);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class WebpackModules {
|
||||||
static async getModuleByProps(props) {
|
static async getModuleByProps(props) {
|
||||||
const modules = await this.getAllModules();
|
const modules = await this.getAllModules();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const rm = [];
|
||||||
for (let index in modules) {
|
for (let index in modules) {
|
||||||
if (!modules.hasOwnProperty(index)) continue;
|
if (!modules.hasOwnProperty(index)) continue;
|
||||||
const module = modules[index];
|
const module = modules[index];
|
||||||
|
@ -20,11 +21,11 @@ class WebpackModules {
|
||||||
|
|
||||||
if (!exports || typeof exports !== 'object') continue;
|
if (!exports || typeof exports !== 'object') continue;
|
||||||
if (!(props in exports)) continue;
|
if (!(props in exports)) continue;
|
||||||
|
rm.push(module);
|
||||||
resolve(module.exports);
|
// resolve(module);
|
||||||
break;
|
// break;
|
||||||
}
|
}
|
||||||
|
resolve(rm);
|
||||||
reject(null);
|
reject(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,11 @@ class WebpackModules {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
for (let index in modules) {
|
for (let index in modules) {
|
||||||
if (!modules.hasOwnProperty(index)) continue;
|
if (!modules.hasOwnProperty(index)) continue;
|
||||||
if (typeof exports === 'object' && name in exports) {
|
const module = modules[index];
|
||||||
|
const { exports } = module;
|
||||||
|
if (!exports) continue;
|
||||||
|
|
||||||
|
if (typeof exports === 'object' && (name in exports || exports.name === name)) {
|
||||||
resolve(module.exports);
|
resolve(module.exports);
|
||||||
break;
|
break;
|
||||||
} else if (typeof exports === 'function' && exports.name === name) {
|
} else if (typeof exports === 'function' && exports.name === name) {
|
||||||
|
|
|
@ -24,8 +24,6 @@ const __DEV = {
|
||||||
clientScriptPath: `${clientScriptPath}/betterdiscord.client.js`
|
clientScriptPath: `${clientScriptPath}/betterdiscord.client.js`
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(__DEV);
|
|
||||||
|
|
||||||
const __pluginPath = path.resolve(__dirname, '..', '..', 'tests', 'plugins');
|
const __pluginPath = path.resolve(__dirname, '..', '..', 'tests', 'plugins');
|
||||||
const __themePath = path.resolve(__dirname, '..', '..', 'tests', 'themes');
|
const __themePath = path.resolve(__dirname, '..', '..', 'tests', 'themes');
|
||||||
|
|
||||||
|
@ -74,6 +72,7 @@ class BetterDiscord {
|
||||||
|
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
this.injectScripts = this.injectScripts.bind(this);
|
this.injectScripts = this.injectScripts.bind(this);
|
||||||
|
this.ignite = this.ignite.bind(this);
|
||||||
Common.Config = new Config(args || dummyArgs);
|
Common.Config = new Config(args || dummyArgs);
|
||||||
this.comms = new Comms();
|
this.comms = new Comms();
|
||||||
this.init();
|
this.init();
|
||||||
|
@ -86,6 +85,28 @@ class BetterDiscord {
|
||||||
const window = yield _this.waitForWindow();
|
const window = yield _this.waitForWindow();
|
||||||
_this.windowUtils = new WindowUtils({ window });
|
_this.windowUtils = new WindowUtils({ window });
|
||||||
|
|
||||||
|
//Log some events for now
|
||||||
|
_this.windowUtils.webContents.on('did-start-loading', function (e) {
|
||||||
|
return _this.windowUtils.executeJavascript(`console.info('did-start-loading');`);
|
||||||
|
});
|
||||||
|
_this.windowUtils.webContents.on('did-stop-loading', function (e) {
|
||||||
|
return _this.windowUtils.executeJavascript(`console.info('did-stop-loading');`);
|
||||||
|
});
|
||||||
|
_this.windowUtils.webContents.on('did-get-response-details', function (e) {
|
||||||
|
return _this.ignite(_this.windowUtils.window);
|
||||||
|
});
|
||||||
|
_this.windowUtils.webContents.on('page-favicon-updated', function (e) {
|
||||||
|
return _this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`);
|
||||||
|
});
|
||||||
|
_this.windowUtils.webContents.on('will-navigate', function (e) {
|
||||||
|
return _this.windowUtils.executeJavascript(`console.info('will-navigate');`);
|
||||||
|
});
|
||||||
|
_this.windowUtils.webContents.on('did-navigate', function (e) {
|
||||||
|
return _this.windowUtils.executeJavascript(`console.info('did-navigate');`);
|
||||||
|
});
|
||||||
|
_this.windowUtils.webContents.on('did-navigate-in-page', function (e) {
|
||||||
|
return _this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`);
|
||||||
|
});
|
||||||
_this.windowUtils.webContents.on('did-finish-load', function (e) {
|
_this.windowUtils.webContents.on('did-finish-load', function (e) {
|
||||||
return _this.injectScripts(true);
|
return _this.injectScripts(true);
|
||||||
});
|
});
|
||||||
|
@ -99,10 +120,20 @@ class BetterDiscord {
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForWindow() {
|
waitForWindow() {
|
||||||
|
var _this2 = this;
|
||||||
|
|
||||||
return _asyncToGenerator(function* () {
|
return _asyncToGenerator(function* () {
|
||||||
|
const self = _this2;
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
const defer = setInterval(function () {
|
const defer = setInterval(function () {
|
||||||
const windows = BrowserWindow.getAllWindows();
|
const windows = BrowserWindow.getAllWindows();
|
||||||
|
|
||||||
|
if (windows.length > 0) {
|
||||||
|
windows.forEach(function (window) {
|
||||||
|
self.ignite(window);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (__DEV && __DEV.TESTING && windows.length > 0) {
|
if (__DEV && __DEV.TESTING && windows.length > 0) {
|
||||||
resolve(windows[0]);
|
resolve(windows[0]);
|
||||||
clearInterval(defer);
|
clearInterval(defer);
|
||||||
|
@ -113,12 +144,19 @@ class BetterDiscord {
|
||||||
resolve(windows[0]);
|
resolve(windows[0]);
|
||||||
clearInterval(defer);
|
clearInterval(defer);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 10);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignite(window) {
|
||||||
|
//Hook things that Discord removes from global. These will be removed again in the client script
|
||||||
|
const sp = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');
|
||||||
|
window.webContents.executeJavaScript(`require("${sp}");`);
|
||||||
|
}
|
||||||
|
|
||||||
injectScripts(reload = false) {
|
injectScripts(reload = false) {
|
||||||
|
console.log(`RELOAD? ${reload}`);
|
||||||
if (__DEV) {
|
if (__DEV) {
|
||||||
this.windowUtils.injectScript(__DEV.clientScriptPath);
|
this.windowUtils.injectScript(__DEV.clientScriptPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
'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
|
||||||
|
};
|
||||||
|
|
||||||
|
window.WebSocket = function (endpoint, protocols) {
|
||||||
|
console.info(`[BetterDiscord|WebSocket Proxy] new WebSocket detected, endpoint: ${endpoint}`);
|
||||||
|
const wsHook = new wsOrig(endpoint, protocols);
|
||||||
|
if (window.__bd.setWS) {
|
||||||
|
window.__bd.setWS(wsHook);
|
||||||
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket sent to instance`);
|
||||||
|
} else {
|
||||||
|
window.__bd['wsHook'] = wsHook;
|
||||||
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to __bd['wsHook']`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wsHook;
|
||||||
|
};
|
||||||
|
})();
|
|
@ -71,6 +71,7 @@ class BetterDiscord {
|
||||||
|
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
this.injectScripts = this.injectScripts.bind(this);
|
this.injectScripts = this.injectScripts.bind(this);
|
||||||
|
this.ignite = this.ignite.bind(this);
|
||||||
Common.Config = new Config(args || dummyArgs);
|
Common.Config = new Config(args || dummyArgs);
|
||||||
this.comms = new Comms();
|
this.comms = new Comms();
|
||||||
this.init();
|
this.init();
|
||||||
|
@ -80,19 +81,33 @@ class BetterDiscord {
|
||||||
const window = await this.waitForWindow();
|
const window = await this.waitForWindow();
|
||||||
this.windowUtils = new WindowUtils({ window });
|
this.windowUtils = new WindowUtils({ window });
|
||||||
|
|
||||||
|
//Log some events for now
|
||||||
|
this.windowUtils.webContents.on('did-start-loading', e => this.windowUtils.executeJavascript(`console.info('did-start-loading');`));
|
||||||
|
this.windowUtils.webContents.on('did-stop-loading', e => this.windowUtils.executeJavascript(`console.info('did-stop-loading');`));
|
||||||
|
this.windowUtils.webContents.on('did-get-response-details', e => this.ignite(this.windowUtils.window));
|
||||||
|
this.windowUtils.webContents.on('page-favicon-updated', e => this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`));
|
||||||
|
this.windowUtils.webContents.on('will-navigate', e => this.windowUtils.executeJavascript(`console.info('will-navigate');`));
|
||||||
|
this.windowUtils.webContents.on('did-navigate', e => this.windowUtils.executeJavascript(`console.info('did-navigate');`));
|
||||||
|
this.windowUtils.webContents.on('did-navigate-in-page', e => this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`));
|
||||||
this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true));
|
this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true));
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (__DEV) {
|
if (__DEV) { this.injectScripts(); }
|
||||||
this.injectScripts();
|
|
||||||
}
|
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForWindow() {
|
async waitForWindow() {
|
||||||
|
const self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const defer = setInterval(() => {
|
const defer = setInterval(() => {
|
||||||
const windows = BrowserWindow.getAllWindows();
|
const windows = BrowserWindow.getAllWindows();
|
||||||
|
|
||||||
|
if (windows.length > 0) {
|
||||||
|
windows.forEach(window => {
|
||||||
|
self.ignite(window);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (__DEV && __DEV.TESTING && windows.length > 0) {
|
if (__DEV && __DEV.TESTING && windows.length > 0) {
|
||||||
resolve(windows[0]);
|
resolve(windows[0]);
|
||||||
clearInterval(defer);
|
clearInterval(defer);
|
||||||
|
@ -103,11 +118,18 @@ class BetterDiscord {
|
||||||
resolve(windows[0]);
|
resolve(windows[0]);
|
||||||
clearInterval(defer);
|
clearInterval(defer);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 10);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignite(window) {
|
||||||
|
//Hook things that Discord removes from global. These will be removed again in the client script
|
||||||
|
const sp = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');
|
||||||
|
window.webContents.executeJavaScript(`require("${sp}");`);
|
||||||
|
}
|
||||||
|
|
||||||
injectScripts(reload = false) {
|
injectScripts(reload = false) {
|
||||||
|
console.log(`RELOAD? ${reload}`);
|
||||||
if (__DEV) {
|
if (__DEV) {
|
||||||
this.windowUtils.injectScript(__DEV.clientScriptPath);
|
this.windowUtils.injectScript(__DEV.clientScriptPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
(() => {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
window.WebSocket = function (endpoint, protocols) {
|
||||||
|
console.info(`[BetterDiscord|WebSocket Proxy] new WebSocket detected, endpoint: ${endpoint}`);
|
||||||
|
const wsHook = new wsOrig(endpoint, protocols);
|
||||||
|
if (window.__bd.setWS) {
|
||||||
|
window.__bd.setWS(wsHook);
|
||||||
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket sent to instance`);
|
||||||
|
} else {
|
||||||
|
window.__bd['wsHook'] = wsHook;
|
||||||
|
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to __bd['wsHook']`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wsHook;
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue