-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
108 lines (90 loc) · 2.92 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
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
const { Plugin } = require('powercord/entities');
const { inject, uninject } = require('powercord/injector');
const { waitFor, getOwnerInstance } = require('powercord/util');
const { React } = require('powercord/webpack');
const { resolve } = require('path');
const Settings = require('./Settings');
module.exports = class Bookmoji extends Plugin {
async startPlugin () {
this.registerSettings(
'bookmoji',
'Bookmoji',
() =>
React.createElement(Settings, {
settings: this.settings
})
);
this.loadCSS(resolve(__dirname, 'style.scss'));
const injection = (self, res) => {
const emojis = this.settings.get('storedEmojis').filter(a => a.constructor === Object);
if (emojis.length) {
const offsetBy = 32;
let total = 0,
index = 0,
row = 0,
column = 0;
let offsetTop = offsetBy * Math.round(emojis.length / 10);
const finalArray = [];
let targetArray = [];
for (const emoji of emojis) {
emoji.available = true;
targetArray.push({
emoji,
offsetTop,
row,
column
});
column++;
index++;
total++;
if (index >= 10 || total >= emojis.length) {
index = 0;
finalArray.push({
category: 'bookmarked',
items: targetArray
});
targetArray = [];
column = 0;
row += 1;
offsetTop += offsetBy;
}
}
for (const category of self.state.metaData) {
for (const emojiContainer of category.items) {
emojiContainer.offsetTop += offsetBy;
emojiContainer.row += row;
}
}
for (const category of self.categories) {
category.offsetTop += offsetBy * Math.round(emojis.length / 10);
self.categoryOffsets[category.category] += offsetBy * Math.round(emojis.length / 10);
}
self.categoryOffsets.bookmarked = 0;
self.categories.unshift({
category: 'bookmarked',
offsetTop: 0,
title: '🔖 Bookmarked'
});
self.cachedMetaDataNoSearch = [ ...finalArray, ...self.state.metaData ];
self.setState({
metaData: self.cachedMetaDataNoSearch
});
return res;
}
};
if (!document.querySelector('.pc-emojiPicker')) {
await waitFor('.pc-emojiPicker');
}
const updateInstance = () =>
(this.instance = getOwnerInstance(document.querySelector('.pc-emojiPicker')));
const instancePrototype = Object.getPrototypeOf(updateInstance());
updateInstance();
inject('bookmoji-emojiPicker', instancePrototype, 'componentDidMount', function (args, res) {
return injection(this, res);
});
this.instance.componentDidMount();
}
pluginWillUnload () {
uninject('bookmoji-emojiPicker');
}
};