This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
forked from intrnl/pc-bdCompat
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
88 lines (69 loc) · 2.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict'
const { Plugin } = require('powercord/entities')
const process = require('process')
const { AddonAPI, BDApi, BDV2, ContentManager, PluginManager } = require('./modules')
const Settings = require('./components/Settings')
module.exports = class BDCompat extends Plugin {
startPlugin () {
this.loadStylesheet('style.css')
this.defineGlobals()
powercord.api.settings.registerSettings('bdCompat', {
category: 'bdCompat',
label: 'BetterDiscord Plugins',
render: Settings
});
}
pluginWillUnload () {
powercord.api.settings.unregisterSettings('bdCompat')
if (window.pluginModule) window.pluginModule.destroy()
if (window.ContentManager) window.ContentManager.destroy()
this.destroyGlobals()
}
defineGlobals () {
let webReq
window.webpackChunkdiscord_app.push([
['bdCompat'],
{},
r => webReq = r
])
window.webpackJsonp = []
window.webpackJsonp.push = ([, mod, [[id]]]) => {
return mod[id]({}, {}, webReq)
}
window.bdConfig = { dataPath: __dirname }
window.settingsCookie = {}
window.bdplugins = {}
window.pluginCookie = {}
window.bdpluginErrors = []
window.bdthemes = {}
window.themeCookie = {}
window.bdthemeErrors = []
// window.BdApi = BDApi
// Orignally BdApi is an object, not a class
window.BdApi = {}
Object.getOwnPropertyNames(BDApi).filter(m => typeof BDApi[m] == 'function' || typeof BDApi[m] == 'object').forEach(m => {
window.BdApi[m] = BDApi[m]
})
window.Utils = { monkeyPatch: BDApi.monkeyPatch, suppressErrors: BDApi.suppressErrors, escapeID: BDApi.escapeID }
window.BDV2 = BDV2
window.ContentManager = new ContentManager
window.pluginModule = new PluginManager(window.ContentManager.pluginsFolder, this.settings)
// DevilBro's plugins checks whether or not it's running on ED
// This isn't BetterDiscord, so we'd be better off doing this.
// eslint-disable-next-line no-process-env
process.env.injDir = __dirname
window.BdApi.Plugins = new AddonAPI(window.bdplugins, window.pluginModule)
window.BdApi.Themes = new AddonAPI({}, {})
this.log('Defined BetterDiscord globals')
}
destroyGlobals () {
const globals = ['bdConfig', 'settingsCookie', 'bdplugins', 'pluginCookie', 'bdpluginErrors', 'bdthemes',
'themeCookie', 'bdthemeErrors', 'BdApi', 'Utils', 'BDV2', 'ContentManager', 'pluginModule', 'webpackJsonp']
globals.forEach(g => {
delete window[g]
})
// eslint-disable-next-line no-process-env
delete process.env.injDir
this.log('Destroyed BetterDiscord globals')
}
}