-
Notifications
You must be signed in to change notification settings - Fork 103
/
NitroPerks.plugin.js
222 lines (213 loc) · 13.7 KB
/
NitroPerks.plugin.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
* @name NitroPerks
* @website https://github.com/respecting/NitroPerks
* @source https://raw.githubusercontent.com/respecting/NitroPerks/main/NitroPerks.plugin.js
* @updateUrl https://raw.githubusercontent.com/respecting/NitroPerks/main/NitroPerks.plugin.js
*/
/*@cc_on
@if (@_jscript)
// Offer to self-install for clueless users that try to run this directly.
var shell = WScript.CreateObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\BetterDiscord\plugins");
var pathSelf = WScript.ScriptFullName;
// Put the user at ease by addressing them in the first person
shell.Popup("It looks like you've mistakenly tried to run me directly. \n(Don't do that!)", 0, "I'm a plugin for BetterDiscord", 0x30);
if (fs.GetParentFolderName(pathSelf) === fs.GetAbsolutePathName(pathPlugins)) {
shell.Popup("I'm in the correct folder already.", 0, "I'm already installed", 0x40);
} else if (!fs.FolderExists(pathPlugins)) {
shell.Popup("I can't find the BetterDiscord plugins folder.\nAre you sure it's even installed?", 0, "Can't install myself", 0x10);
} else if (shell.Popup("Should I copy myself to BetterDiscord's plugins folder for you?", 0, "Do you need some help?", 0x34) === 6) {
fs.CopyFile(pathSelf, fs.BuildPath(pathPlugins, fs.GetFileName(pathSelf)), true);
// Show the user where to put plugins in the future
shell.Exec("explorer " + pathPlugins);
shell.Popup("I'm installed!", 0, "Successfully installed", 0x40);
}
WScript.Quit();
@else@*/
module.exports = (() => {
const config = {
"info": {
"name": "NitroPerks",
"authors": [{
"name": "lemons",
"discord_id": "407348579376693260",
"github_username": "respecting"
}],
"version": "1.3.1",
"description": "Unlock all screensharing modes, and use cross-server emotes & gif emotes, Discord wide! (You CANNOT upload 100MB files though. :/)",
"github": "https://github.com/respecting/NitroPerks",
"github_raw": "https://raw.githubusercontent.com/respecting/NitroPerks/master/NitroPerks.plugin.js"
},
"main": "NitroPerks.plugin.js"
};
return !global.ZeresPluginLibrary ? class {
constructor() {
this._config = config;
}
getName() {
return config.info.name;
}
getAuthor() {
return config.info.authors.map(a => a.name).join(", ");
}
getDescription() {
return config.info.description;
}
getVersion() {
return config.info.version;
}
load() {
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (error, response, body) => {
if (error) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
});
}
});
}
start() {}
stop() {}
} : (([Plugin, Api]) => {
const plugin = (Plugin, Api) => {
const {
Patcher,
DiscordModules,
DiscordAPI,
Settings,
Toasts,
PluginUtilities
} = Api;
return class NitroPerks extends Plugin {
defaultSettings = {
"emojiSize": 40,
"screenSharing": false,
"emojiBypass": true,
"clientsidePfp": false,
"pfpUrl": "",
};
settings = PluginUtilities.loadSettings(this.getName(), this.defaultSettings);
originalNitroStatus = 0;
clientsidePfp;
screenShareFix;
getSettingsPanel() {
return Settings.SettingPanel.build(_ => this.saveAndUpdate(), ...[
new Settings.SettingGroup("Emoji Size").append(
new Settings.Textbox("Size", "A number from 16 to 64.", this.settings.emojiSize,
size => {
if (isNaN(size)) return Toasts.error("Please input a number.")
if (size < 16) return Toasts.error("Please input a number above 16!")
if (size > 64) return Toasts.error("Please input a number below 64!")
this.settings.emojiSize = size
}
)
),
new Settings.SettingGroup("Features").append(...[
new Settings.Switch("High Quality Screensharing", "Enable or disable 1080p/source @ 60fps screensharing. This adapts to your current nitro status.", this.settings.screenSharing, value => this.settings.screenSharing = value),
new Settings.Switch("Nitro Emotes Bypass", "Enable or disable using the Nitro Emote bypass.", this.settings.emojiBypass, value => this.settings.emojiBypass = value),
new Settings.Switch("Clientsided Profile Picture", "Enable or disable clientsided profile pictures.", this.settings.clientsidePfp, value => this.settings.clientsidePfp = value)
]),
new Settings.SettingGroup("Profile Picture").append(...[
new Settings.Textbox("URL", "The direct URL that has the profile picture you want.", this.settings.pfpUrl,
image => {
try {
new URL(image)
} catch {
return Toasts.error('This is an invalid URL!')
}
this.settings.pfpUrl = image
}
)
])
])
}
saveAndUpdate() {
PluginUtilities.saveSettings(this.getName(), this.settings)
if (!this.settings.screenSharing) {
switch (this.originalNitroStatus) {
case 1:
BdApi.injectCSS("screenShare", `#app-mount > div.layerContainer-yqaFcK > div.layer-2KE1M9 > div > div > form > div:nth-child(2) > div > div > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6.modalContent-BM7Qeh > div:nth-child(1) > div > button:nth-child(4) {
display: none;
}`)
this.screenShareFix = setInterval(()=>{
document.querySelector("#app-mount > div.layerContainer-yqaFcK > div.layer-2KE1M9 > div > div > form > div:nth-child(2) > div > div > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6.modalContent-BM7Qeh > div:nth-child(1) > div > button:nth-child(3)").click()
clearInterval(this.screenShareFix)
}, 100)
break;
default: //if user doesn't have nitro?
BdApi.injectCSS("screenShare", `#app-mount > div.layerContainer-yqaFcK > div.layer-2KE1M9 > div > div > form > div:nth-child(2) > div > div > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6.modalContent-BM7Qeh > div:nth-child(1) > div > button:nth-child(4) {
display: none;
}
#app-mount > div.layerContainer-yqaFcK > div.layer-2KE1M9 > div > div > form > div:nth-child(2) > div > div > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6.modalContent-BM7Qeh > div:nth-child(1) > div > button:nth-child(3) {
display: none;
}
#app-mount > div.layerContainer-yqaFcK > div.layer-2KE1M9 > div > div > form > div:nth-child(2) > div > div > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6.modalContent-BM7Qeh > div:nth-child(2) > div > button:nth-child(3) {
display: none;
}`)
this.screenShareFix = setInterval(()=>{
document.querySelector("#app-mount > div.layerContainer-yqaFcK > div.layer-2KE1M9 > div > div > form > div:nth-child(2) > div > div > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6.modalContent-BM7Qeh > div:nth-child(1) > div > button:nth-child(2)").click()
document.querySelector("#app-mount > div.layerContainer-yqaFcK > div.layer-2KE1M9 > div > div > form > div:nth-child(2) > div > div > div.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6.modalContent-BM7Qeh > div:nth-child(2) > div > button:nth-child(2)").click()
clearInterval(this.screenShareFix)
}, 100)
break;
}
}
if (this.settings.screenSharing) BdApi.clearCSS("screenShare")
if (this.settings.emojiBypass) {
//fix emotes with bad method
Patcher.before(DiscordModules.MessageActions, "sendMessage", (_, [, msg]) => {
msg.validNonShortcutEmojis.forEach(emoji => {
if (emoji.url.startsWith("/assets/")) return;
msg.content = msg.content.replace(`<${emoji.animated ? "a" : ""}${emoji.allNamesString.replace(/~\d/g, "")}${emoji.id}>`, emoji.url + `&size=${this.settings.emojiSize} `)
})
});
//for editing message also
Patcher.before(DiscordModules.MessageActions, "editMessage", (_,obj) => {
let msg = obj[2].content
if (msg.search(/\d{18}/g) == -1) return;
msg.match(/<a:.+?:\d{18}>|<:.+?:\d{18}>/g).forEach(idfkAnymore=>{
obj[2].content = obj[2].content.replace(idfkAnymore, `https://cdn.discordapp.com/emojis/${idfkAnymore.match(/\d{18}/g)[0]}?size=${this.settings.emojiSize}`)
})
});
}
if(!this.settings.emojiBypass) Patcher.unpatchAll(DiscordModules.MessageActions)
if (this.settings.clientsidePfp && this.settings.pfpUrl) {
this.clientsidePfp = setInterval(()=>{
document.querySelectorAll(`[src="${DiscordAPI.currentUser.discordObject.avatarURL.replace(".png", ".webp")}"]`).forEach(avatar=>{
avatar.src = this.settings.pfpUrl
})
document.querySelectorAll(`[src="${DiscordAPI.currentUser.discordObject.avatarURL}"]`).forEach(avatar=>{
avatar.src = this.settings.pfpUrl
})
}, 100)
}
if (!this.settings.clientsidePfp) this.removeClientsidePfp()
}
removeClientsidePfp() {
clearInterval(this.clientsidePfp)
document.querySelectorAll(`[src="${this.settings.pfpUrl}"]`).forEach(avatar=>{
avatar.src = DiscordAPI.currentUser.discordObject.avatarURL
})
document.querySelectorAll(`[src="${this.settings.pfpUrl}"]`).forEach(avatar=>{
avatar.src = DiscordAPI.currentUser.discordObject.avatarURL
})
}
onStart() {
this.originalNitroStatus = DiscordAPI.currentUser.discordObject.premiumType;
this.saveAndUpdate()
DiscordAPI.currentUser.discordObject.premiumType = 2
}
onStop() {
DiscordAPI.currentUser.discordObject.premiumType = this.originalNitroStatus;
this.removeClientsidePfp()
Patcher.unpatchAll();
}
};
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();
/*@end@*/