forked from NurMarvin/discord-tweaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (64 loc) · 2.11 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
const { resolve } = require('path');
const { Plugin } = require('powercord/entities');
const { React } = require('powercord/webpack');
const Settings = require('./components/Settings');
const tweaks = require('./tweaks.json');
const fs = require('fs');
module.exports = class DiscordTweaks extends Plugin {
registeredTweaksJS = []
async startPlugin() {
const toggleTweak = tweak => {
this.toggleTweak(tweak)
};
const toggleTweakJS = tweakid => {
this.toggleTweakJS(tweakid);
}
const getSettings = (key, defaultValue) => this.settings.get(key, defaultValue);
this.loadCSS(resolve(__dirname, 'style.scss'))
this.registerSettings('discord-tweaks', 'Discord Tweaks', (props) =>
React.createElement(Settings, {
toggleTweak,
toggleTweakJS,
tweaks,
...props
})
);
tweaks.forEach(tweak => {
let tweakName = tweak.name.toLowerCase().replace(/ /g, '-');
if (getSettings(tweakName)) {
toggleTweak(tweakName);
}
});
}
toggleTweak(tweakId) {
const id = `discord-tweaks-${tweakId}`;
if (fs.existsSync(resolve(`${__dirname}/tweaks/${tweakId}`, `tweak.scss`))) {
const style = document.getElementById(`powercord-css-${id}`);
if (!style) {
this.loadCSS(id, resolve(`${__dirname}/tweaks/${tweakId}`, `tweak.scss`));
} else {
this.unloadCSS(id);
}
}
if (fs.existsSync(resolve(`${__dirname}/tweaks/${tweakId}`, `tweak.js`))) {
const tweak = this.registeredTweaksJS.find(t => t.id == tweakId)
if (!tweak) {
const tweakjs = require(`${__dirname}/tweaks/${tweakId}/tweak.js`);
tweakjs.enable();
this.registeredTweaksJS.push({ id: tweakId, ...tweakjs });
} else {
tweak.disable();
this.registeredTweaksJS.splice(this.registeredTweaksJS.indexOf(tweak), 1);
}
}
}
unloadCSS(id) {
const { styles } = this.registered;
for (let i = 0; i < styles.length; i++) {
if (styles[i] === id) {
this.registered.styles.splice(i, 1);
}
}
powercord.styleManager.themes.get(id).remove();
}
};