-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
69 lines (60 loc) · 2.75 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
import * as webpackModules from '@goosemod/webpack';
import * as patcher from '@goosemod/patcher';
import { createItem, removeItem } from '@goosemod/settings';
let settings = { emojisize: '64' };
const emojisModule = webpackModules.findByProps('getDisambiguatedEmojiContext', 'search');
const messageEmojiParserModule = webpackModules.findByProps('parse', 'parsePreprocessor', 'unparse');
const emojiPickerModule = webpackModules.findByProps('useEmojiSelectHandler');
const Unpatch = {};
export default {
goosemodHandlers: {
onImport: async () => {
Unpatch.emojisModule = patcher.patch(emojisModule, "search", (originalArgs, previousReturn) => {
previousReturn.unlocked.push(...previousReturn.locked);
previousReturn.locked = [];
return previousReturn;
});
Unpatch.messageEmojiParserModule = patcher.patch(messageEmojiParserModule, "parse", (originalArgs, previousReturn) => {
if (previousReturn.invalidEmojis.length !== 0) {
for (let emoji of previousReturn.invalidEmojis) {
previousReturn.content = previousReturn.content.replace(
`<${emoji.animated ? 'a' : ''}:${emoji.originalName || emoji.name}:${emoji.id}>`,
`${emoji.url.split('?')[0]}?size=${settings.emojisize}&width=16`,
);
}
previousReturn.invalidEmojis = [];
}
return previousReturn;
});
Unpatch.emojiPickerModule = patcher.patch(emojiPickerModule, "useEmojiSelectHandler", (originalArgs, previousReturn) => {
const {
onSelectEmoji,
closePopout
} = originalArgs[0];
return function(data, state) {
const emoji = data.emoji;
if (emoji != null && emoji.available) {
onSelectEmoji(emoji, state.isFinalSelection);
if (state.isFinalSelection) closePopout();
}
};
});
createItem('Emote as URL', ['',
{
type: 'text-input',
text: 'Emoji Size',
initialValue: () => settings.emojisize,
oninput: (value) => {
settings.emojisize = value;
},
},
]);
},
getSettings: () => [settings],
loadSettings: ([_settings]) => { settings = _settings },
onRemove: async () => {
Object.values(Unpatch).forEach(unpatch => unpatch());
removeItem('Emote as URL');
}
},
};