forked from An00nymushun/DiscordFreeEmojis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FreeEmojis.plugin.js
196 lines (157 loc) · 7.11 KB
/
FreeEmojis.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
/**
* @name FreeEmojis
* @version 2.1
* @description Link emojis if you don't have nitro! Type them out or use the emoji picker! [64px]
* @author An0, nk34player
* @source https://github.com/nk34player/FreeEmojis
* @updateUrl https://raw.githubusercontent.com/nk34player/FreeEmojis/master/DiscordFreeEmojis64px.plugin.js
*/
var FreeEmojis = (() => {
'use strict';
const BaseColor = "#0cf";
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 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) {
if (emoji.animated != true){
parseResult.content = parseResult.content.replace(`<${emoji.animated ? "a" : ""}:${emoji.originalName || emoji.name}:${emoji.id}>`, "https://cdn.discordapp.com/emojis/"+ emoji.id + ".webp" + "?size=64");
} else {
parseResult.content = parseResult.content.replace(`<${emoji.animated ? "a" : ""}:${emoji.originalName || emoji.name}:${emoji.id}>`, "https://cdn.discordapp.com/emojis/"+ emoji.id + ".gif" + "?size=64");
}
}
parseHook = function() {
let result = original_parse.apply(this, arguments);
if(result.invalidEmojis.length !== 0) {
for(let emoji of result.invalidEmojis) {
console.log(emoji)
replaceEmoji(result, emoji);
}
result.invalidEmojis = [];
}
let validNonShortcutEmojis = result.validNonShortcutEmojis;
for (let i = 0; i < validNonShortcutEmojis.length; i++) {
const emoji = validNonShortcutEmojis[i];
if(!emoji.available) {
replaceEmoji(result, emoji);
validNonShortcutEmojis.splice(i, 1);
i--;
}
}
return result;
};
getEmojiUnavailableReasonHook = function() {
return null;
}
}
function Stop() {
if(!Initialized) return;
searchHook = Discord.original_searchWithoutFetchingLatest;
parseHook = Discord.original_parse;
getEmojiUnavailableReasonHook = Discord.original_getEmojiUnavailableReason;
}
return function() { return {
getName: () => "FreeEmojis",
getShortName: () => "FreeEmojis",
getDescription: () => "Link emojis if you don't have nitro! Type them out or use the emoji picker!",
getVersion: () => "2.1",
getAuthor: () => "An0, nk34player",
getSettingsPanel() {
let size = BdApi.loadData('FreeEmojis', 'EmojiSize');
const div = document.createElement('div');
div.style = `padding: 20px; display:none`;
let SettingsHTML = `<div style="color:white;text-align: center;"><h1>WIP</h1></div>`;
div.innerHTML = SettingsHTML;
setTimeout(()=>this.onSettings(div, size), 100);
return div;
},
onSettings(panel, size) {
panel.style = `padding: 20px; display:block`;
console.log(size)
},
start: Start,
stop: Stop
}};
})();
module.exports = FreeEmojis;
/*@end @*/