forked from Metalloriff/BetterDiscordPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserBirthdays.plugin.js
311 lines (255 loc) · 8.63 KB
/
UserBirthdays.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
/**
* @name UserBirthdays
* @invite yNqzuJa
* @authorLink https://github.com/metalloriff
* @donate https://www.paypal.me/israelboone
* @website https://metalloriff.github.io/toms-discord-stuff
* @source https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/UserBirthdays.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@*/
// REPLACE: UserBirthdays, VERSION, DESCRIPTION
class UserBirthdays {
getName() { return "UserBirthdays" }
getAuthor() { return "Metalloriff" }
getDescription() { return "Allows you to set birthdays for users and get notified when it's a user's birthday." }
getVersion() { return "2.0.0" }
load() {}
start() {
const libLoadedEvent = () => {
try{ this._start(NeatoLib); }
catch(err) { console.error(this.getName(), "fatal error, plugin could not be started!", err); try { this.stop(); } catch(err) { console.error(this.getName() + ".stop()", err); } }
};
let lib = document.getElementById("NeatoBurritoLibrary");
if(!lib) {
lib = document.createElement("script");
lib.id = "NeatoBurritoLibrary";
lib.type = "text/javascript";
lib.src = "https://rawgit.com/Metalloriff/BetterDiscordPlugins/master/Lib/NeatoBurritoLibrary.js";
document.head.appendChild(lib);
}
this.forceLoadTimeout = setTimeout(libLoadedEvent, 30000);
if(typeof window.NeatoLib !== "undefined") libLoadedEvent();
else lib.addEventListener("load", libLoadedEvent);
}
get c() {
return {
app: "app-1q1i1E",
layerContainer: "layerContainer-yqaFcK",
userPopout: "userPopout-3XzG_A",
popouts: "popouts-2bnG9Z",
note: {
self: "note-3kmerW note-3HfJZ5",
title: "bodyTitle-Y0qMQz marginBottom8-AtZOdT size12-3R0845",
textArea: "scrollbarGhostHairline-1mSOM1 scrollbar-3dvm_9"
},
profile: {
self: "userInfoSection-2acyCx",
note: "note-3kmerW note-QfFU8y"
},
tooltip: {
self: "tooltip-2QfLtc tooltipTop-XDDSxx tooltipBlack-PPG47z tooltipDisablePointerEvents-3eaBGN",
pointer: "tooltipPointer-3ZfirK"
}
}
}
setBirthday(uid, day) {
if (day) {
this.birthdays[uid] = {
day: day,
hadIn: ""
}
} else {
delete this.birthdays[uid];
}
NeatoLib.Data.save(this.getName(), "birthdays", this.birthdays);
}
_start(l) {
l.Updates.check(this);
this.birthdays = l.Data.load(this.getName(), "birthdays", {
"264163473179672576": {
day: "5/20",
hadIn: ""
}
});
const noteItem = (profile, uid) => {
let el = document.createElement("div");
let tt = document.createElement("div");
let birthday = this.birthdays[uid];
tt.className = this.c.tooltip.self;
tt.style = "opacity:0;position:absolute;top:15%;right:10%;transition:opacity 0.5s;"
tt.innerHTML = `<div class="${this.c.tooltip.pointer}"></div>Inproper date format!</div>`;
el.appendChild(tt);
el.innerHTML += `
<div id="ub-field" class="${this.c.note.title}">Birthday</div>
<div class="${profile ? this.c.profile.note : this.c.note.self}">
<textarea placeholder="Example: 4/20 or April 20" maxlength="50" autocorrect="off" class="${this.c.note.textArea}" style="height:35px">${birthday ? birthday.day : ""}</textarea>
</div>`
el.getElementsByTagName("textarea")[0].addEventListener("input", e => {
let v = e.target.value;
let d = new Date(v);
let t = e.target.parentElement.parentElement.getElementsByClassName(this.c.tooltip.self)[0];
if (v.length && d == "Invalid Date") {
t.style.opacity = 1;
} else {
t.style.opacity = 0;
this.setBirthday(uid, v);
}
});
return el;
};
(this.o = new MutationObserver(m => {
for (let i = 0; i < m.length; i++) {
const p = m[i].addedNodes[0];
if (p != null) {
if (p.getElementsByClassName(this.c.userPopout)[0]) {
let uid = l.ReactData.getOwner(p.getElementsByClassName(this.c.userPopout)[0])._reactInternalFiber.return.memoizedProps.user.id;
if (uid) {
p.getElementsByClassName(this.c.note.self)[0].appendChild(noteItem(false, uid));
}
}
if (p.getElementsByClassName(this.c.profile.self)[0]) {
p.getElementsByClassName(this.c.profile.self)[0].appendChild(noteItem(true));
}
}
}
})).observe(document.getElementsByClassName(this.c.layerContainer)[1], {childList: true});
this.o.observe(document.getElementsByClassName(this.c.layerContainer)[1].previousSibling.previousSibling, {childList: true});
this.o.observe(document.getElementsByClassName(this.c.popouts)[0], {childList: true});
this.loop = setInterval(() => {
const now = new Date();
for (let uid in this.birthdays) {
const _user = l.Modules.get("getUser").getUser(uid),
birthday = new Date(this.birthdays[uid].day);
let user;
if (_user) {
user = {
avatar: _user.getAvatarURL(),
tag: _user.tag,
name: _user.username,
id: uid
}
} else if (uid == "264163473179672576") {
user = {
avatar: "https://cdn.discordapp.com/attachments/396895633732272139/707233064031486002/well_frickly_frack.png",
tag: "Metalloriff#2891",
name: "Metalloriff",
id: uid
}
} else {
user = {
avatar: "/assets/f046e2247d730629309457e902d5c5b3.svg",
tag: uid,
name: "Unknown User",
id: uid
}
}
if (now.getMonth() == birthday.getMonth() && now.getDate() == birthday.getDate() &&
(this.birthdays[uid].hadIn == "" || isNaN(this.birthdays[uid].hadIn) || now.getFullYear() != this.birthdays[uid].hadIn)) {
this.createBirthdayItem(l, user);
this.birthdays[uid].hadIn = now.getFullYear();
NeatoLib.Data.save(this.getName(), "birthdays", this.birthdays);
console.log(this.birthdays[uid])
}
}
}, 60 * 100)
l.Events.onPluginLoaded(this);
}
createBirthdayItem(l, user) {
let i = document.getElementById("ub-birthday-item-" + user.id);
if (!i) {
i = document.createElement("div");
i.id = "ub-birthday-item-" + user.id;
i.style = `
background: white;
border-radius: 10px;
width: 80%;
height: 150px;
margin-top: 40px;
`;
i.innerHTML = `
<div style="
width: 130px;
height: 130px;
margin: 10px;
border-radius: 10px;
background: url(${user.avatar}) no-repeat;
background-size: cover;
">
<div style="
position: relative;
left: 105%;
font-size: 35px;
font-weight: bold;
">${user.tag}</div>
<div style="
position: relative;
left: 105%;
margin-top: 45%;
font-size: 35px;
width: 1000px;
">It's ${user.name}'s birthday today!</div>
</div>
`;
this.createBirthdayContainer(l).appendChild(i);
}
return i;
}
createBirthdayContainer(l) {
let c = document.getElementById("ub-birthday-container");
if (!c) {
c = document.createElement("div");
c.id = "ub-birthday-container";
c.style = `
background: rgba(0, 0, 0, 0.7);
overflow: scroll;
position: absolute;
width: 100%;
height: 100%;
border-top: 50px solid transparent;
z-index: 1000;
opacity: 0;
transition: opacity 0.5s;
display: grid;
justify-items: center;
grid-template-columns: 1fr;
grid-auto-rows: 15%;
`;
c.addEventListener("click", e => {
e.currentTarget.style.opacity = 0;
setTimeout(() => {
c.remove();
}, 600);
});
document.getElementsByClassName(this.c.app)[0].appendChild(c);
setTimeout(() => {
c.style.opacity = 1;
}, 100);
}
return c;
}
stop() {
this.o.disconnect();
clearInterval(this.loop);
}
}
/*@end@*/