Skip to content
This repository has been archived by the owner on Jun 27, 2021. It is now read-only.

Commit

Permalink
ModalStack -> ModalActions fixes #146
Browse files Browse the repository at this point in the history
  • Loading branch information
rauenzi committed Sep 25, 2020
1 parent 9bf2d9a commit c565ed9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
6 changes: 3 additions & 3 deletions bd_shit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = class BDManager {
fs.readFile(path.join(process.env.injDir, 'bd.css'), (err, text) => {
if (err) return console.error(err);
EDApi.injectCSS('BDManager', text);
})
});

Module._extensions['.js'] = this.pluginRequire();
}
Expand Down Expand Up @@ -89,8 +89,8 @@ module.exports = class BDManager {
}

static isEmpty(obj) {
if (obj == null || obj == undefined || obj == "") return true;
if (typeof(obj) !== "object") return false;
if (obj == null || obj == undefined || obj == '') return true;
if (typeof(obj) !== 'object') return false;
if (Array.isArray(obj)) return obj.length == 0;
for (const key in obj) {
if (obj.hasOwnProperty(key)) return false;
Expand Down
61 changes: 31 additions & 30 deletions dom_shit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Module = window.require('module').Module;
Module.globalPaths.push(path.resolve(electron.remote.app.getAppPath(), 'node_modules'));
const currentWindow = electron.remote.getCurrentWindow();
if (currentWindow.__preload) {
process.electronBinding("command_line").appendSwitch("preload", currentWindow.__preload)
process.electronBinding('command_line').appendSwitch('preload', currentWindow.__preload);
electron.contextBridge.exposeInMainWorld = (key, val) => window[key] = val; // Expose DiscordNative
require(currentWindow.__preload);
}
Expand Down Expand Up @@ -40,7 +40,8 @@ const c = {
setTimeout(resolve, ms);
});
}
}
};

// config util
window.ED = { plugins: {}, version: '2.8' };
Object.defineProperty(ED, 'config', {
Expand Down Expand Up @@ -159,7 +160,7 @@ process.once('loaded', async () => {

await new Promise(resolve => {
d.resolve = resolve;
})
});
c.log(`Modules done loading (${Object.keys(window.req.c).length})`);

if (ED.config.bdPlugins) {
Expand Down Expand Up @@ -198,13 +199,13 @@ process.once('loaded', async () => {
}


const ht = EDApi.findModule('hideToken')
const ht = EDApi.findModule('hideToken');
// prevent client from removing token from localstorage when dev tools is opened, or reverting your token if you change it
EDApi.monkeyPatch(ht, 'hideToken', () => {});
window.fixedShowToken = () => {
// Only allow this to add a token, not replace it. This allows for changing of the token in dev tools.
if (!ED.localStorage || ED.localStorage.getItem('token')) return;
return ED.localStorage.setItem('token', '"'+ht.getToken()+'"');
return ED.localStorage.setItem('token', '"' + ht.getToken() + '"');
};
EDApi.monkeyPatch(ht, 'showToken', window.fixedShowToken);
if (!ED.localStorage.getItem('token') && ht.getToken())
Expand All @@ -220,7 +221,7 @@ process.once('loaded', async () => {
console.log('%cUnless you understand exactly what you\'re doing, keep this window open to browse our bad code.', 'font-size: 16px;');
console.log('%cIf you don\'t understand exactly what you\'re doing, you should come work with us: https://discordapp.com/jobs', 'font-size: 16px;');
});
})
});



Expand Down Expand Up @@ -284,10 +285,10 @@ window.EDApi = window.BdApi = class EDApi {
* @param {string} [options.key] - key used to identify the modal. If not provided, one is generated and returned
* @returns {string} - the key used for this modal
*/
static showConfirmationModal(title, content, options = {}) {
const ModalStack = this.findModuleByProps('push', 'update', 'pop', 'popWithKey');
static showConfirmationModal(title, content, options = {}) {
const ModalActions = this.findModuleByProps('openModal', 'updateModal');
const Markdown = this.findModuleByDisplayName('Markdown');
const ConfirmationModal = this.findModuleByDisplayName("ConfirmModal");
const ConfirmationModal = this.findModuleByDisplayName('ConfirmModal');
if (!ModalActions || !ConfirmationModal || !Markdown) return window.alert(content);

const emptyFunction = () => {};
Expand Down Expand Up @@ -350,13 +351,13 @@ window.EDApi = window.BdApi = class EDApi {
}

static showToast(content, options = {}) {
if (!document.querySelector('.toasts')) {
if (!document.querySelector('.toasts')) {
const container = document.querySelector('.sidebar-2K8pFh + div') || null;
const memberlist = container ? container.querySelector('.membersWrap-2h-GB4') : null;
const form = container ? container.querySelector('form') : null;
const left = container ? container.getBoundingClientRect().left : 310;
const right = memberlist ? memberlist.getBoundingClientRect().left : 0;
const width = right ? right - container.getBoundingClientRect().left : Utils.screenWidth - left - 240;
const width = right ? right - container.getBoundingClientRect().left : Math.max(document.documentElement.clientWidth, window.innerWidth || 0) - left - 240;
const bottom = form ? form.offsetHeight : 80;
const toastWrapper = document.createElement('div');
toastWrapper.classList.add('toasts');
Expand Down Expand Up @@ -390,7 +391,7 @@ window.EDApi = window.BdApi = class EDApi {
if (m && (moduleName ? m[moduleName] : filter(m))) return m;
}
}
if (!silent) c.warn(`Could not find module ${module}.`, {name: 'Modules', color: 'black'})
if (!silent) c.warn(`Could not find module ${module}.`, {name: 'Modules', color: 'black'});
return null;
}

Expand All @@ -405,7 +406,7 @@ window.EDApi = window.BdApi = class EDApi {
return window.req.c[i];
}
}
if (!silent) c.warn(`Could not find module ${module}.`, {name: 'Modules', color: 'black'})
if (!silent) c.warn(`Could not find module ${module}.`, {name: 'Modules', color: 'black'});
return null;
}

Expand Down Expand Up @@ -496,20 +497,20 @@ window.EDApi = window.BdApi = class EDApi {
return string;
}

static isPluginEnabled(name) {
const plugins = Object.values(ED.plugins);
const plugin = plugins.find(p => p.id == name || p.name == name);
if (!plugin) return false;
return !(plugin.settings.enabled === false);
}
static isPluginEnabled(name) {
const plugins = Object.values(ED.plugins);
const plugin = plugins.find(p => p.id == name || p.name == name);
if (!plugin) return false;
return !(plugin.settings.enabled === false);
}

static isThemeEnabled() {
return false;
}
static isThemeEnabled() {
return false;
}

static isSettingEnabled(id) {
return ED.config[id];
}
static isSettingEnabled(id) {
return ED.config[id];
}
};

window.BdApi.Plugins = new class AddonAPI {
Expand All @@ -518,9 +519,9 @@ window.BdApi.Plugins = new class AddonAPI {

isEnabled(name) {
const plugins = Object.values(ED.plugins);
const plugin = plugins.find(p => p.id == name || p.name == name);
if (!plugin) return false;
return !(plugin.settings.enabled === false);
const plugin = plugins.find(p => p.id == name || p.name == name);
if (!plugin) return false;
return !(plugin.settings.enabled === false);
}

enable(name) {
Expand Down Expand Up @@ -577,7 +578,7 @@ window.BdApi.loadData = function(pluginName, key) {

if (!ED.plugins[id]) return null;
return this.loadPluginSettings(id)[key];
}
};

window.BdApi.saveData = function(pluginName, key, data) {
const pl = Object.values(ED.plugins).find(p => p.name === pluginName);
Expand All @@ -587,4 +588,4 @@ window.BdApi.saveData = function(pluginName, key, data) {
const obj = this.loadPluginSettings(id);
obj[key] = data;
return this.savePluginSettings(id, obj);
}
};

0 comments on commit c565ed9

Please sign in to comment.