-
Notifications
You must be signed in to change notification settings - Fork 358
/
UserBirthdays.plugin.js
331 lines (282 loc) · 13.8 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/**
* @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@*/
module.exports = (() => {
const config = {
"info": {
"name": "UserBirthdays",
"authors": [{
"name": "Metalloriff",
"discord_id": "264163473179672576",
"github_username": "Metalloriff",
"twitter_username": "Metalloriff"
}],
"version": "3.0.0",
"description": "Allows you to set birthdays for users and get notified when it's a user's birthday.",
"github": "https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/UserBirthdays.plugin.js",
"github_raw": "https://raw.githubusercontent.com/Metalloriff/BetterDiscordPlugins/master/UserBirthdays.plugin.js"
},
"changelog": [{
"title": "Rewritten!",
"type": "improved",
"items": ["UserBirthdays fixed by Danielle#1788"]
}]
};
return !global.ZeresPluginLibrary ? class {
constructor() {
this._config = config;
}
getName() {
return config.info.name;
}
getAuthor() {
return config.info.authors.map(a => a.name).join(", ");
}
getDescription() {
return config.info.description;
}
getVersion() {
return config.info.version;
}
load() {
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (error, response, body) => {
if (error) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
});
}
});
}
start() {}
stop() {}
} : (([Plugin, Api]) => {
const plugin = (Plugin, Api) => {
const {
Toasts,
PluginUtilities,
DiscordModules
} = Api;
const {
UserStore
} = DiscordModules;
return class UserBirthdays extends Plugin {
onStart() {
this.birthdays = PluginUtilities.loadData(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;animation: none;"
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, April 20 or YYYY-MM-DD" 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 = p.getElementsByClassName(this.c.userPopout)[0].dataset.userId;
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, p.getElementsByClassName(this.c.profile.self)[0].parentElement.parentElement.parentElement.dataset.userId));
}
}
}
})).observe(document.getElementsByClassName(this.c.layerContainer)[1], {
childList: true
});
this.o.observe(document.getElementsByClassName(this.c.layerContainer)[1].previousSibling.previousElementSibling, {
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 = UserStore.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(user);
this.birthdays[uid].hadIn = now.getFullYear();
PluginUtilities.saveData(this.getName(), "birthdays", this.birthdays);
}
}
}, 60 * 1000)
}
onStop() {
this.o.disconnect();
clearInterval(this.loop);
}
get c() {
return {
app: "app-1q1i1E",
layerContainer: "layerContainer-yqaFcK",
userPopout: "userPopout-xaxa6l",
popouts: "popouts-2bnG9Z",
note: {
self: "note-1oo11U",
title: "bodyTitle-1ySSKn base-1x0h_U size12-3cLvbJ",
textArea: "textarea-2r0oV8 scrollbarGhostHairline-1mSOM1 scrollbar-3dvm_9"
},
profile: {
self: "userInfoSection-q_35fn",
note: "note-367eZJ"
},
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];
}
PluginUtilities.saveData(this.getName(), "birthdays", this.birthdays);
Toasts.success("Birthday Set!")
}
createBirthdayItem(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%; font-size: 35px; width: 1000px;">It's ${user.name}'s birthday today!</div>
</div>`;
this.createBirthdayContainer().appendChild(i);
}
return i;
}
createBirthdayContainer() {
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;
}
};
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();
/*@end@*/