forked from An00nymushun/DiscordFreeEmojis
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDiscordFreeEmojis.plugin.js
358 lines (288 loc) · 13.6 KB
/
DiscordFreeEmojis.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/**
* @name FreeEmojis
* @version 1.8.6-hotfix
* @description Link emojis if you don't have nitro! Type them out or use the emoji picker!
* @author An0 (Original) & EpicGazel
* @source https://github.com/EpicGazel/DiscordFreeEmojis
* @updateUrl https://raw.githubusercontent.com/EpicGazel/DiscordFreeEmojis/master/DiscordFreeEmojis.plugin.js
*/
/*@cc_on
@if (@_jscript)
var shell = WScript.CreateObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\\BetterDiscord\\plugins");
var pathSelf = WScript.ScriptFullName;
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 @*/
var FreeEmojis = (() => {
'use strict';
const { createElement, useState } = BdApi.React;
//const FormSwitch = BdApi.Webpack.getByKeys("FormSwitch").FormSwitch;
const FormSwitch = null;
const BaseColor = "#0cf";
const DOM = BdApi.DOM;
const hideNitroCSSString = `button[class*='emojiItemDisabled'] {
filter: none !important;
outline: dotted 4px rgba(255, 255, 255, 0.46);
outline-offset: -2px;
cursor: pointer !important;
}
/* Makes the dark background transparent */
[class*="emojiLockIconContainer_"] {
background: rgba(0,0,0,0) !important;
scale: 0.01 !important;
}
/* Makes the emoji lock icon itself too small to see */
[class*="emojiLockIcon_"] {
width: 0 !important;
}
/* Hides lock on server icons */
[class*="categoryItemLockIconContainer_"] {
display: none;
}
/* Hides the "Unlock every emoji with Nitro - Get Nitro" pop-up */
[class*="upsellContainer_"] {
display: none;
}
/* Hides the divider between "Frequently Used" and server emojis */
[class*="categorySectionNitroTopDivider_"] {
display: none;
}
/* Makes the pink background behind "locked" emojis transparent. */
[class*="categorySectionNitroLocked_"] {
background-color: transparent;
}
`;
const miscellaneousCSS = `/* Other misc rules */
/* Make (normal) text emojis bigger */
.emoji.jumboable {
width:150px;
height:150px;
}
/* Really big emoji/sticker/gif drawer */
[class*="positionLayer_"] { /*.positionLayer_af5dbb*/
height: calc(100vh - 220px);
}
/* Hide send gift button */
button[aria-label="Send a gift"] {
visibility: hidden;
display: none;
}`;
var css = "";
var Discord;
var Utils = {
Log: (message) => { console.log(`%c[FreeEmojis] %c${message}`, `color:${BaseColor};font-weight:bold`, "") },
Warn: (message) => { console.warn(`%c[FreeEmojis] %c${message}`, `color:${BaseColor};font-weight:bold`, "") },
Error: (message) => { console.error(`%c[FreeEmojis] %c${message}`, `color:${BaseColor};font-weight:bold`, "") },
Webpack: () => {
let webpackExports;
if(typeof BdApi !== "undefined" && BdApi?.findModuleByProps && BdApi?.findModule) {
return { findModule: BdApi.findModule, findModuleByUniqueProperties: (props) => BdApi.findModuleByProps.apply(null, props) };
}
else if(Discord.window.webpackChunkdiscord_app != null) {
Discord.window.webpackChunkdiscord_app.push([
['__extra_id__'],
{},
req => webpackExports = req
]);
}
else if(Discord.window.webpackJsonp != null) {
webpackExports = typeof(Discord.window.webpackJsonp) === 'function' ?
Discord.window.webpackJsonp(
[],
{ '__extra_id__': (module, _export_, req) => { _export_.default = req } },
[ '__extra_id__' ]
).default :
Discord.window.webpackJsonp.push([
[],
{ '__extra_id__': (_module_, exports, req) => { _module_.exports = req } },
[ [ '__extra_id__' ] ]
]);
}
else return null;
delete webpackExports.m['__extra_id__'];
delete webpackExports.c['__extra_id__'];
const findModule = (filter) => {
for(let i in webpackExports.c) {
if(webpackExports.c.hasOwnProperty(i)) {
let m = webpackExports.c[i].exports;
if(!m) continue;
if(m.__esModule && m.default) m = m.default;
if(filter(m)) return m;
}
}
return null;
};
const findModuleByUniqueProperties = (propNames) => findModule(module => propNames.every(prop => module[prop] !== undefined));
return { findModule, findModuleByUniqueProperties };
}
};
var pluginSettings = {
useNativeEmojiSize: {
name: "Use native emoji size",
note: "Uploads emoji as their native size. Always scales down to 48px, the Discord emoji size, otherwise.",
value: true,
type: FormSwitch
},
hideNitroCss: {
name: "Hide Nitro CSS",
note: "Removes Nitro adds using CSS.",
value: true,
type: FormSwitch
},
enableMiscellaneousCSS:{
name: "Enable Miscellaneous CSS properties",
note: "Other CSS styles that you may or may not like. Bigger emojis, bigger emoji drawer, hide gift button...",
value: false,
type: FormSwitch
}
};
var Initialized = false;
var searchHook;
var parseHook;
var getEmojiUnavailableReasonHook;
function Init()
{
Discord = { window: (typeof(unsafeWindow) !== 'undefined') ? unsafeWindow : window };
const webpackUtil = Utils.Webpack();
if(webpackUtil == null) { Utils.Error("Webpack not found."); return 0; }
const { findModule, findModuleByUniqueProperties } = webpackUtil;
let emojisModule = findModuleByUniqueProperties([ 'getDisambiguatedEmojiContext', 'searchWithoutFetchingLatest' ]);
if(emojisModule == null) { Utils.Error("emojisModule not found."); return 0; }
let messageEmojiParserModule = findModuleByUniqueProperties([ 'parse', 'parsePreprocessor', 'unparse' ]);
if(messageEmojiParserModule == null) { Utils.Error("messageEmojiParserModule not found."); return 0; }
let emojiPermissionsModule = findModuleByUniqueProperties([ 'getEmojiUnavailableReason' ]);
if(emojiPermissionsModule == null) { Utils.Error("emojiPermissionsModule not found."); return 0; }
searchHook = Discord.original_searchWithoutFetchingLatest = emojisModule.searchWithoutFetchingLatest;
emojisModule.searchWithoutFetchingLatest = function() { return searchHook.apply(this, arguments); };
parseHook = Discord.original_parse = messageEmojiParserModule.parse;
messageEmojiParserModule.parse = function() { return parseHook.apply(this, arguments); };
getEmojiUnavailableReasonHook = Discord.original_getEmojiUnavailableReason = emojiPermissionsModule.getEmojiUnavailableReason;
emojiPermissionsModule.getEmojiUnavailableReason = function() { return getEmojiUnavailableReasonHook.apply(this, arguments); };
Utils.Log("initialized");
Initialized = true;
return 1;
}
function Start() {
if(!Initialized && Init() !== 1) return;
const { original_parse, original_getEmojiUnavailableReason } = Discord;
searchHook = function() {
let result = Discord.original_searchWithoutFetchingLatest.apply(this, arguments);
console.log({result, arguments})
result.unlocked.push(...result.locked);
result.locked = [];
return result;
}
function replaceEmoji(parseResult, emoji, index) {
let emojiUrl = `https://cdn.discordapp.com/emojis/${emoji.id}.${emoji.animated ? "gif" : "webp"}?quality=lossless&${index}${pluginSettings.useNativeEmojiSize.value ? "" : "&size=48"}`;
parseResult.content = parseResult.content.replace
(`<${emoji.animated ? "a" : ""}:${emoji.originalName || emoji.name}:${emoji.id}>`,
`[󠄀](${emojiUrl}) `);
}
parseHook = function() {
let result = original_parse.apply(this, arguments);
let emojisSent = 0;
if(result.invalidEmojis.length !== 0) {
for(let emoji of result.invalidEmojis) {
let index = Math.floor(Math.random() * 100000);
replaceEmoji(result, emoji, index);
}
result.invalidEmojis = [];
}
let validNonShortcutEmojis = result.validNonShortcutEmojis;
for (let i = 0; i < validNonShortcutEmojis.length; i++) {
const emoji = validNonShortcutEmojis[i];
if(!emoji.available) {
replaceEmoji(result, emoji, emojisSent);
emojisSent++;
validNonShortcutEmojis.splice(i, 1);
i--;
}
}
return result;
};
getEmojiUnavailableReasonHook = function() {
return null;
}
for (let key in pluginSettings) {
const loadedSetting = BdApi.Data.load("FreeEmojis", key);
if (loadedSetting == undefined) {
BdApi.Data.save("FreeEmojis", key, pluginSettings[key].value);
} else {
pluginSettings[key].value = loadedSetting;
}
}
// Set CSS
if (pluginSettings.hideNitroCss.value)
css += hideNitroCSSString;
if (pluginSettings.enableMiscellaneousCSS.value)
css += miscellaneousCSS;
DOM.addStyle('FreeEmojis', css)
}
function Stop() {
if(!Initialized) return;
searchHook = Discord.original_searchWithoutFetchingLatest;
parseHook = Discord.original_parse;
getEmojiUnavailableReasonHook = Discord.original_getEmojiUnavailableReason;
DOM.removeStyle('FreeEmojis')
}
function GetSettingsPanel() {
const settingsElement = () => {
const [usePluginSettings, setPluginSettings] = useState(pluginSettings);
const handleChange = (key, value) => {
let updatedSettings = { ...usePluginSettings };
updatedSettings[key].value = value
setPluginSettings(updatedSettings);
BdApi.Data.save("FreeEmojis", key, value);
// Update CSS
css = "";
if (pluginSettings.hideNitroCss.value)
css += hideNitroCSSString;
if (pluginSettings.enableMiscellaneousCSS.value)
css += miscellaneousCSS;
// Reload CSS
DOM.removeStyle('FreeEmojis')
DOM.addStyle('FreeEmojis', css)
}
return Object.keys(pluginSettings).map((key) => {
const { type } = pluginSettings[key];
let outputElement;
if (type == FormSwitch) {
let { name, note, value } = pluginSettings[key];
outputElement = createElement(FormSwitch, {
name: name,
children: name,
note: note,
value: value,
onChange: (v) => handleChange(key, v)
});
}
return outputElement;
});
};
return createElement(settingsElement);
}
return function() { return {
getName: () => "DiscordFreeEmojis",
getShortName: () => "FreeEmojis",
getDescription: () => "Link emojis if you don't have nitro! Type them out or use the emoji picker!",
getVersion: () => "1.8.0",
getAuthor: () => "An0 (Original) & EpicGazel",
start: Start,
stop: Stop,
getSettingsPanel: GetSettingsPanel
}};
})();
module.exports = FreeEmojis;
/*@end @*/