aboutsummaryrefslogtreecommitdiff
path: root/.config/BetterDiscord/plugins/EditChannels.plugin.js
blob: 955776e2d84f2e13f4bd64f0b2c5379af95ff62f (plain)
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
//META{"name":"EditChannels","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/EditChannels","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/EditChannels/EditChannels.plugin.js"}*//

var EditChannels = (_ => {
	return class EditChannels {
		getName () {return "EditChannels";}

		getVersion () {return "4.1.3";}

		getAuthor () {return "DevilBro";}

		getDescription () {return "Allows you to rename and recolor channelnames.";}

		constructor () {
			this.changelog = {
				"fixed":[["Context Menu Update","Fixes for the context menu update, yaaaaaay"]]
			};

			this.patchedModules = {
				before: {
					ChannelEditorContainer: "render",
					ChannelAutoComplete: "render",
					AutocompleteChannelResult: "render",
					AuditLog: "render",
					SettingsInvites: "render",
					HeaderBarContainer: "render",
					ChannelCategoryItem: "render",
					ChannelItem: "render",
					QuickSwitchChannelResult: "render",
					MessageContent: "type"
				},
				after: {
					AutocompleteChannelResult: "render",
					AuditLog: "render",
					HeaderBarContainer: "render",
					ChannelCategoryItem: "render",
					ChannelItem: "render",
					QuickSwitchChannelResult: "render",
					MessagesPopout: "render"
				}
			};
		}

		initConstructor () {
			this.css = `
				${BDFDB.dotCN.messagespopoutchannelname}:hover > span[style*="color"] {
					text-decoration: underline;
				}
				${BDFDB.dotCN.categorywrapper}:hover ${BDFDB.dotCN.categoryname} span[style*="color"],
				${BDFDB.dotCN.categorywrapper}:hover ${BDFDB.dotCN.categoryicon}.EC-changed,
				${BDFDB.dotCN.channelwrapper + BDFDB.notCN.channelmodeselected + BDFDB.notCN.channelmodeconnected}:hover ${BDFDB.dotCN.channelname} span[style*="color"],
				${BDFDB.dotCN.channelwrapper + BDFDB.notCN.channelmodeselected + BDFDB.notCN.channelmodeconnected}:hover ${BDFDB.dotCN.channelicon}.EC-changed {
					filter: brightness(150%);
				}
			`;

			this.defaults = {
				settings: {
					changeChannelIcon:		{value:true, 	inner:false,	description:"Change color of Channel Icon"},
					changeInChatTextarea:	{value:true, 	inner:true,		description:"Chat Textarea"},
					changeInMentions:		{value:true, 	inner:true,		description:"Mentions"},
					changeInChannelList:	{value:true, 	inner:true,		description:"Channel List"},
					changeInChannelHeader:	{value:true, 	inner:true,		description:"Channel Header"},
					changeInRecentMentions:	{value:true, 	inner:true,		description:"Recent Mentions Popout"},
					changeInAutoComplete:	{value:true, 	inner:true,		description:"Autocomplete Menu"},
					changeInAuditLog:		{value:true, 	inner:true,		description:"Audit Log"},
					changeInInviteLog:		{value:true, 	inner:true,		description:"Invite Log"},
					changeInQuickSwitcher:	{value:true, 	inner:true,		description:"Quick Switcher"}
				}
			};
		}

		getSettingsPanel () {
			if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
			let settings = BDFDB.DataUtils.get(this, "settings");
			let settingsPanel, settingsItems = [], innerItems = [];
			
			for (let key in settings) (!this.defaults.settings[key].inner ? settingsItems : innerItems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
				className: BDFDB.disCN.marginbottom8,
				type: "Switch",
				plugin: this,
				keys: ["settings", key],
				label: this.defaults.settings[key].description,
				value: settings[key]
			}));
			settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
				title: "Change Channels in:",
				first: settingsItems.length == 0,
				children: innerItems
			}));
			settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
				type: "Button",
				className: BDFDB.disCN.marginbottom8,
				color: BDFDB.LibraryComponents.Button.Colors.RED,
				label: "Reset all Channels",
				onClick: _ => {
					BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all channels?", _ => {
						BDFDB.DataUtils.remove(this, "channels");
						this.forceUpdateAll();
					});
				},
				children: BDFDB.LanguageUtils.LanguageStrings.RESET
			}));
			
			return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
		}

		// Legacy
		load () {}

		start () {
			if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
			if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
			let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
			if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
				if (libraryScript) libraryScript.remove();
				libraryScript = document.createElement("script");
				libraryScript.setAttribute("id", "BDFDBLibraryScript");
				libraryScript.setAttribute("type", "text/javascript");
				libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
				libraryScript.setAttribute("date", performance.now());
				libraryScript.addEventListener("load", _ => {this.initialize();});
				document.head.appendChild(libraryScript);
			}
			else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
			this.startTimeout = setTimeout(_ => {
				try {return this.initialize();}
				catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
			}, 30000);
		}

		initialize () {
			if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
				if (this.started) return;
				BDFDB.PluginUtils.init(this);

				let observer = new MutationObserver(_ => {this.changeAppTitle();});
				BDFDB.ObserverUtils.connect(this, document.head.querySelector("title"), {name:"appTitleObserver",instance:observer}, {childList:true});
				
				this.forceUpdateAll();
			}
			else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
		}

		stop () {
			if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
				this.stopping = true;

				let data = BDFDB.DataUtils.load(this, "channels");
				BDFDB.DataUtils.remove(this, "channels");
				try {this.forceUpdateAll();} catch (err) {}
				BDFDB.DataUtils.save(data, this, "channels");

				BDFDB.PluginUtils.clear(this);
			}
		}


		// Begin of own functions

		onChannelContextMenu (e) {
			if (e.instance.props.channel) {
				let [children, index] = BDFDB.ContextMenuUtils.findItem(e.returnvalue, {id: "devmode-copy-id", group: true});
				children.splice(index > -1 ? index : children.length, 0, BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
					children: BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
						label: this.labels.context_localchannelsettings_text,
						id: BDFDB.ContextMenuUtils.createItemId(this.name, "settings-submenu"),
						children: BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
							children: [
								BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
									label: this.labels.submenu_channelsettings_text,
									id: BDFDB.ContextMenuUtils.createItemId(this.name, "settings-change"),
									action: _ => {
										BDFDB.ContextMenuUtils.close(e.instance);
										this.openChannelSettingsModal(e.instance.props.channel);
									}
								}),
								BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
									label: this.labels.submenu_resetsettings_text,
									id: BDFDB.ContextMenuUtils.createItemId(this.name, "settings-reset"),
									disabled: !BDFDB.DataUtils.load(this, "channels", e.instance.props.channel.id),
									action: _ => {
										BDFDB.ContextMenuUtils.close(e.instance);
										BDFDB.DataUtils.remove(this, "channels", e.instance.props.channel.id);
										this.forceUpdateAll();
									}
								})
							]
						})
					})
				}));
			}
		}

		onSettingsClosed () {
			if (this.SettingsUpdated) {
				delete this.SettingsUpdated;
				this.forceUpdateAll();
			}
		}
		
		processChannelEditorContainer (e) {
			if (!e.instance.props.disabled && e.instance.props.channel && BDFDB.ChannelUtils.isTextChannel(e.instance.props.channel) && e.instance.props.type == BDFDB.DiscordConstants.TextareaTypes.NORMAL && BDFDB.DataUtils.get(this, "settings", "changeInChatTextarea")) {
				let data = BDFDB.DataUtils.load(this, "channels", e.instance.props.channel.id);
				e.instance.props.placeholder = BDFDB.LanguageUtils.LanguageStringsFormat("TEXTAREA_PLACEHOLDER", `#${data && data.name || e.instance.props.channel.name}`);
			}
		}

		processChannelAutoComplete (e) {
			if (e.instance.state.autocompleteType == "CHANNELS" && BDFDB.ArrayUtils.is(e.instance.state.autocompletes.channels) && e.instance.props.channel && e.instance.props.channel.guild_id) {
				let lastword = (e.instance.props.textValue || "").slice(1).toLowerCase();
				let channels = BDFDB.DataUtils.load(this, "channels");
				if (!channels || !lastword) return;
				let channelarray = [];
				for (let id in channels) if (channels[id] && channels[id].name) {
					let channel = BDFDB.LibraryModules.ChannelStore.getChannel(id);
					let category = channel && channel.parent_id && BDFDB.LibraryModules.ChannelStore.getChannel(channel.parent_id);
					let catdata = category && channels[category.id] || {};
					if (BDFDB.ChannelUtils.isTextChannel(channel) && channel.guild_id == e.instance.props.channel.guild_id) channelarray.push(Object.assign({
						lowercasename: channels[id].name.toLowerCase(),
						lowercasecatname: catdata && catdata.name && catdata.name.toLowerCase(),
						channel,
						category,
						catdata
					}, channels[id]));
				}
				channelarray = BDFDB.ArrayUtils.keySort(channelarray.filter(n => e.instance.state.autocompletes.channels.every(channel => channel.id != n.channel.id) && (n.lowercasename.indexOf(lastword) != -1 || (n.lowercasecatname && n.lowercasecatname.indexOf(lastword) != -1))), "lowercasename");
				e.instance.state.autocompletes.channels = [].concat(e.instance.state.autocompletes.channels, channelarray.map(n => n.channel)).slice(0, BDFDB.DiscordConstants.MAX_AUTOCOMPLETE_RESULTS);
			}
		}

		processAutocompleteChannelResult (e) {
			if (e.instance.props.channel && BDFDB.DataUtils.get(this, "settings", "changeInAutoComplete")) {
				if (!e.returnvalue) {
					e.instance.props.channel = this.getChannelData(e.instance.props.channel.id);
					if (e.instance.props.category) e.instance.props.category = this.getChannelData(e.instance.props.category.id);
				}
				else {
					let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.marginleft4]]});
					if (index > -1) this.changeChannelColor(children[index], e.instance.props.channel.id);
					[children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.autocompleteicon]]});
					if (index > -1) this.changeChannelIconColor(children[index], e.instance.props.channel.id, {alpha: 0.6});
					if (e.instance.props.category) {
						[children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.autocompletedescription]]});
						if (index > -1) this.changeChannelColor(children[index], e.instance.props.category.id);
					}
				}
			}
		}

		processAuditLog (e) {
			let channel = BDFDB.ReactUtils.getValue(e.instance, "props.log.options.channel");
			if (channel && BDFDB.DataUtils.get(this, "settings", "changeInAuditLog")) {
				if (!e.returnvalue) e.instance.props.log.options.channel = this.getChannelData(channel.id);
				else {
					let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["children", [["#" + channel.name]]]]});
					if (index > -1) this.changeChannelColor(children[index], channel.id);
				}
			}
		}

		processSettingsInvites (e) {
			if (BDFDB.ObjectUtils.is(e.instance.props.invites) && BDFDB.DataUtils.get(this, "settings", "changeInInviteLog")) {
				e.instance.props.invites = Object.assign({}, e.instance.props.invites);
				for (let id in e.instance.props.invites) e.instance.props.invites[id] = new BDFDB.DiscordObjects.Invite(Object.assign({}, e.instance.props.invites[id], {channel: this.getChannelData(e.instance.props.invites[id].channel.id)}));
			}
		}

		processHeaderBarContainer (e) {
			let channel = BDFDB.LibraryModules.ChannelStore.getChannel(e.instance.props.channelId);
			if (channel && BDFDB.ChannelUtils.isTextChannel(channel) && BDFDB.DataUtils.get(this, "settings", "changeInChannelHeader")) {
				if (!e.returnvalue) {
					let [children, index] = BDFDB.ReactUtils.findChildren(e.instance, {name: "Title"});
					if (index > -1) {
						children[index].props.children = this.getChannelData(channel.id).name;
						this.changeChannelColor(children[index], channel.id);
					}
				}
				else {
					let [children, index] = BDFDB.ReactUtils.findChildren(e.instance, {name: "Icon"});
					if (index > -1) {
						let icon = BDFDB.ReactUtils.createElement(children[index].props.icon, {
							className: BDFDB.disCN.channelheadericon
						});
						this.changeChannelIconColor(icon, channel.id, {alpha: 0.6});
						children[index] = BDFDB.ReactUtils.createElement("div", {
							className: BDFDB.disCN.channelheadericonwrapper,
							children: icon
						})
					}
				}
			}
		}

		processChannelCategoryItem (e) {
			if (e.instance.props.channel && BDFDB.DataUtils.get(this, "settings", "changeInChannelList")) {
				if (!e.returnvalue) e.instance.props.channel = this.getChannelData(e.instance.props.channel.id);
				else {
					let modify = BDFDB.ObjectUtils.extract(e.instance.props, "muted", "locked", "selected", "unread", "connected");
					let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.categoryname]]});
					if (index > -1) this.changeChannelColor(children[index], e.instance.props.channel.id, modify);
					[children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.categoryicon]]});
					if (index > -1) this.changeChannelIconColor(children[index], e.instance.props.channel.id, Object.assign({alpha: 0.6}, modify));
				}
			}
		}

		processChannelItem (e) {
			if (e.instance.props.channel && BDFDB.DataUtils.get(this, "settings", "changeInChannelList")) {
				if (!e.returnvalue) e.instance.props.channel = this.getChannelData(e.instance.props.channel.id);
				else {
					let modify = BDFDB.ObjectUtils.extract(e.instance.props, "muted", "locked", "selected", "unread", "connected");
					let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.channelname]]});
					if (index > -1) this.changeChannelColor(children[index], e.instance.props.channel.id, modify);
					[children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.channelicon]]});
					if (index > -1) this.changeChannelIconColor(children[index], e.instance.props.channel.id, Object.assign({alpha: 0.6}, modify));
				}
			}
		}
		
		processQuickSwitchChannelResult (e) {
			if (e.instance.props.channel && BDFDB.DataUtils.get(this, "settings", "changeInQuickSwitcher")) {
				if (!e.returnvalue) {
					e.instance.props.channel = this.getChannelData(e.instance.props.channel.id);
					if (e.instance.props.category) e.instance.props.category = this.getChannelData(e.instance.props.category.id);
				}
				else {
					let modify = BDFDB.ObjectUtils.extract(e.instance.props, "focused", "unread", "mentions");
					let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.quickswitchresultmatch]]});
					if (index > -1) this.changeChannelColor(children[index], e.instance.props.channel.id, modify);
					[children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.quickswitchresulticon]]});
					if (index > -1) this.changeChannelIconColor(children[index], e.instance.props.channel.id, Object.assign({alpha: 0.6}, modify));
					if (e.instance.props.category) {
						[children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.quickswitchresultnote]]});
						if (index > -1) this.changeChannelColor(children[index], e.instance.props.category.id);
					}
				}
			}
		}
		
		processMessagesPopout (e) {
			if (BDFDB.DataUtils.get(this, "settings", "changeInRecentMentions")) {
				let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "VerticalScroller"});
				if (index > -1 && children[index].props.children && BDFDB.ArrayUtils.is(children[index].props.children[0])) for (let i in children[index].props.children[0]) {
					let divider = children[index].props.children[0][i];
					if (divider && divider.props && divider.props.className == BDFDB.disCN.messagespopoutchannelseparator) {
						let channel = BDFDB.ReactUtils.findValue(children[index].props.children[0][parseInt(i)+1], "channel");
						if (BDFDB.ChannelUtils.isTextChannel(channel)) {
							let [children2, index2] = BDFDB.ReactUtils.findChildren(divider, {props:[["className", BDFDB.disCN.messagespopoutchannelname]]});
							if (index2 > -1) {
								children2[index2].props.children = "#" + this.getChannelData(channel.id).name;
								this.changeChannelColor(children2[index2], channel.id);
							}
						}
					}
				}
			}
		}

		processMessageContent (e) {
			if (BDFDB.ArrayUtils.is(e.instance.props.content) && BDFDB.DataUtils.get(this, "settings", "changeInMentions")) for (let ele of e.instance.props.content) {
				if (BDFDB.ReactUtils.isValidElement(ele) && ele.type && ele.type.displayName == "Tooltip" && typeof ele.props.children == "function") {
					let children = ele.props.children({});
					if (children && children.type.displayName == "Mention" && children.props.children && typeof children.props.children[0] == "string" && children.props.children[0][0] == "#") {
						let channelName = children.props.children[0].slice(1);
						let guildId = BDFDB.LibraryModules.LastGuildStore.getGuildId();
						let channels = guildId && (BDFDB.LibraryModules.GuildChannelStore.getChannels(guildId)[0] || BDFDB.LibraryModules.GuildChannelStore.getChannels(guildId).SELECTABLE);
						if (Array.isArray(channels)) for (let channelObj of channels) {
							if (channelName == channelObj.channel.name) {
								let category = BDFDB.LibraryModules.ChannelStore.getChannel(channelObj.channel.parent_id);
								if (!category || category && ele.props.text == category.name) {
									if (category) {
										let categoryData = BDFDB.DataUtils.load(this, "channels", category.id);
										if (categoryData && categoryData.name) ele.props.text = categoryData.name;
									}
									let name = (BDFDB.DataUtils.load(this, "channels", channelObj.channel.id) || {}).name;
									let color = this.getChannelDataColor(channelObj.channel.id);
									if (name || color) {
										let renderChildren = ele.props.children;
										ele.props.children = (...args) => {
											let renderedChildren = renderChildren(...args);
											if (name) renderedChildren.props.children[0] = "#" + name;
											if (color) {
												let color1_0 = BDFDB.ColorUtils.convert(BDFDB.ObjectUtils.is(color) ? color[0] : color, "RGBA");
												let color0_1 = BDFDB.ColorUtils.setAlpha(color1_0, 0.1, "RGBA");
												let color0_7 = BDFDB.ColorUtils.setAlpha(color1_0, 0.7, "RGBA");
												renderedChildren.props.style = Object.assign({}, renderedChildren.props.style, {
													background: color0_1,
													color: color1_0
												});
												let onMouseEnter = renderedChildren.props.onMouseEnter || ( _ => {});
												renderedChildren.props.onMouseEnter = event => {
													onMouseEnter(event);
													event.target.style.setProperty("background", color0_7, "important");
													event.target.style.setProperty("color", "#FFFFFF", "important");
												};
												let onMouseLeave = renderedChildren.props.onMouseLeave || ( _ => {});
												renderedChildren.props.onMouseLeave = event => {
													onMouseLeave(event);
													event.target.style.setProperty("background", color0_1, "important");
													event.target.style.setProperty("color", color1_0, "important");
												};
											}
											return renderedChildren;
										}
									}
									break;
								}
							}
						}
					}
				}
			}
		}

		changeAppTitle () {
			let channel = BDFDB.LibraryModules.ChannelStore.getChannel(BDFDB.LibraryModules.LastChannelStore.getChannelId());
			let title = document.head.querySelector("title");
			if (title && BDFDB.ChannelUtils.isTextChannel(channel)) BDFDB.DOMUtils.setText(title, "@" + this.getChannelData(channel.id, BDFDB.DataUtils.get(this, "settings", "changeAppTitle")).name);
		}
		
		changeChannelColor (child, channelId, modify) {
			let color = this.getChannelDataColor(channelId);
			if (color) {
				color = modify ? this.chooseColor(color, modify) : BDFDB.ColorUtils.convert(color, "RGBA");
				let fontGradient = BDFDB.ObjectUtils.is(color);
				if (fontGradient) child.props.children = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextGradientElement, {
					gradient: BDFDB.ColorUtils.createGradient(color),
					children: child.props.children
				});
				else child.props.children = BDFDB.ReactUtils.createElement("span", {
					style: {color: color},
					children: child.props.children
				});
			}
		}
		
		changeChannelIconColor (child, channelId, modify) {
			let color = this.getChannelDataColor(channelId);
			if (color && BDFDB.DataUtils.get(this, "settings", "changeChannelIcon")) {
				color = modify ? this.chooseColor(BDFDB.ObjectUtils.is(color) ? color[0] : color, modify) : BDFDB.ColorUtils.convert(BDFDB.ObjectUtils.is(color) ? color[0] : color, "RGBA");
				child.props.color = color || "currentColor";
				if (color) {
					child.props.foreground = null;
					child.props.className = BDFDB.DOMUtils.formatClassName(child.props.className, "EC-changed");
				}
			}
		}

		chooseColor (color, config) {
			if (color) {
				if (BDFDB.ObjectUtils.is(config)) {
					if (config.mentions || config.focused || config.hovered || config.selected || config.unread || config.connected) color = BDFDB.ColorUtils.change(color, 0.5);
					else if (config.muted || config.locked) color = BDFDB.ColorUtils.change(color, -0.5);
				}
				return BDFDB.ColorUtils.convert(color, "RGBA");
			}
			return null;
		}
		
		getChannelDataColor (channelId) {
			let channel = BDFDB.LibraryModules.ChannelStore.getChannel(channelId);
			if (!channel) return null;
			let channelData = BDFDB.DataUtils.load(this, "channels", channel.id);
			if (channelData && channelData.color) return channelData.color;
			let category = channel.parent_id && BDFDB.LibraryModules.ChannelStore.getChannel(channel.parent_id);
			if (category) {
				let categoryData = BDFDB.DataUtils.load(this, "channels", category.id);
				if (categoryData && categoryData.inheritColor && categoryData.color) return categoryData.color;
			}
			return null;
		}
		
		getChannelData (channelId, change = true) {
			let channel = BDFDB.LibraryModules.ChannelStore.getChannel(channelId);
			if (!channel) return new BDFDB.DiscordObjects.Channel({});
			let data = change && BDFDB.DataUtils.load(this, "channels", channel.id);
			if (data) {
				let nativeObject = new BDFDB.DiscordObjects.Channel(channel);
				nativeObject.name = data.name || nativeObject.name;
				return nativeObject;
			}
			return new BDFDB.DiscordObjects.Channel(channel);
		}
		
		forceUpdateAll () {
			this.changeAppTitle();
			BDFDB.ModuleUtils.forceAllUpdates(this);
			BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:"Channel", unlimited:true}));
		}

		openChannelSettingsModal (channel) {
			let data = BDFDB.DataUtils.load(this, "channels", channel.id) || {};
			
			BDFDB.ModalUtils.open(this, {
				size: "MEDIUM",
				header: this.labels.modal_header_text,
				subheader: channel.name,
				children: [
					BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
						title: this.labels.modal_channelname_text,
						className: BDFDB.disCN.marginbottom20 + " input-channelname",
						children: [
							BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
								value: data.name,
								placeholder: channel.name,
								autoFocus: true
							}),
							BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
								className: BDFDB.disCN.dividerdefault
							})
						]
					}),
					BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
						title: this.labels.modal_colorpicker1_text,
						className: BDFDB.disCN.marginbottom20,
						children: [
							BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ColorSwatches, {
								color: data.color,
								number: 1
							})
						]
					}),
					BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
						type: "Switch",
						className: BDFDB.disCN.marginbottom20 + " input-inheritcolor",
						label: this.labels.modal_inheritcolor_text,
						tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H5,
						value: channel.type == 4 && data.inheritColor,
						disabled: channel.type != 4
					})
				],
				buttons: [{
					contents: BDFDB.LanguageUtils.LanguageStrings.SAVE,
					color: "BRAND",
					close: true,
					click: modal => {
						let olddata = Object.assign({}, data);
						
						data.name = modal.querySelector(".input-channelname " + BDFDB.dotCN.input).value.trim() || null;

						data.color = BDFDB.ColorUtils.getSwatchColor(modal, 1);
						if (data.color != null && !BDFDB.ObjectUtils.is(data.color)) {
							if (data.color[0] < 30 && data.color[1] < 30 && data.color[2] < 30) data.color = BDFDB.ColorUtils.change(data.color, 30);
							else if (data.color[0] > 225 && data.color[1] > 225 && data.color[2] > 225) data.color = BDFDB.ColorUtils.change(data.color, -30);
						}

						data.inheritColor = modal.querySelector(".input-inheritcolor " + BDFDB.dotCN.switchinner).checked;
						
						let changed = false;
						if (Object.keys(data).every(key => data[key] == null || data[key] == false) && (changed = true)) BDFDB.DataUtils.remove(this, "channels", channel.id);
						else if (!BDFDB.equals(olddata, data) && (changed = true)) BDFDB.DataUtils.save(data, this, "channels", channel.id);
						if (changed) this.forceUpdateAll();
					}
				}]
			});
		}

		setLabelsByLanguage () {
			switch (BDFDB.LanguageUtils.getLanguage().id) {
				case "hr":		//croatian
					return {
						context_localchannelsettings_text:		"Postavke lokalnih kanala",
						submenu_channelsettings_text:			"Promijeni postavke",
						submenu_resetsettings_text:				"Vraćanje kanala",
						modal_header_text:						"Postavke lokalnih kanala",
						modal_channelname_text:					"Naziv lokalnog kanala",
						modal_colorpicker1_text:				"Boja lokalnog kanala",
						modal_inheritcolor_text:				"Naslijedi boju u potkanale"
					};
				case "da":		//danish
					return {
						context_localchannelsettings_text:		"Lokal kanalindstillinger",
						submenu_channelsettings_text:			"Skift indstillinger",
						submenu_resetsettings_text:				"Nulstil kanal",
						modal_header_text:						"Lokal kanalindstillinger",
						modal_channelname_text:					"Lokalt kanalnavn",
						modal_colorpicker1_text:				"Lokal kanalfarve",
						modal_inheritcolor_text:				"Arve farve til subkanaler"
					};
				case "de":		//german
					return {
						context_localchannelsettings_text:		"Lokale Kanaleinstellungen",
						submenu_channelsettings_text:			"Einstellungen ändern",
						submenu_resetsettings_text:				"Kanal zurücksetzen",
						modal_header_text:						"Lokale Kanaleinstellungen",
						modal_channelname_text:					"Lokaler Kanalname",
						modal_colorpicker1_text:				"Lokale Kanalfarbe",
						modal_inheritcolor_text:				"Farbe an Unterkanäle vererben"
					};
				case "es":		//spanish
					return {
						context_localchannelsettings_text:		"Ajustes local de canal",
						submenu_channelsettings_text:			"Cambiar ajustes",
						submenu_resetsettings_text:				"Restablecer canal",
						modal_header_text:						"Ajustes local de canal",
						modal_channelname_text:					"Nombre local del canal",
						modal_colorpicker1_text:				"Color local del canal",
						modal_inheritcolor_text:				"Heredar color a sub-canales"
					};
				case "fr":		//french
					return {
						context_localchannelsettings_text:		"Paramètres locale du salon",
						submenu_channelsettings_text:			"Modifier les paramètres",
						submenu_resetsettings_text:				"Réinitialiser le salon",
						modal_header_text:						"Paramètres locale du salon",
						modal_channelname_text:					"Nom local du salon",
						modal_colorpicker1_text:				"Couleur locale du salon",
						modal_inheritcolor_text:				"Hériter de la couleur sur les sous-salons"
					};
				case "it":		//italian
					return {
						context_localchannelsettings_text:		"Impostazioni locale canale",
						submenu_channelsettings_text:			"Cambia impostazioni",
						submenu_resetsettings_text:				"Ripristina canale",
						modal_header_text:						"Impostazioni locale canale",
						modal_channelname_text:					"Nome locale canale",
						modal_colorpicker1_text:				"Colore locale canale",
						modal_inheritcolor_text:				"Eredita colore per sub-canali"
					};
				case "nl":		//dutch
					return {
						context_localchannelsettings_text:		"Lokale kanaalinstellingen",
						submenu_channelsettings_text:			"Verandere instellingen",
						submenu_resetsettings_text:				"Reset kanaal",
						modal_header_text:						"Lokale kanaalinstellingen",
						modal_channelname_text:					"Lokale kanaalnaam",
						modal_colorpicker1_text:				"Lokale kanaalkleur",
						modal_inheritcolor_text:				"Overerving van kleuren naar subkanalen"
					};
				case "no":		//norwegian
					return {
						context_localchannelsettings_text:		"Lokal kanalinnstillinger",
						submenu_channelsettings_text:			"Endre innstillinger",
						submenu_resetsettings_text:				"Tilbakestill kanal",
						modal_header_text:						"Lokal kanalinnstillinger",
						modal_channelname_text:					"Lokalt kanalnavn",
						modal_colorpicker1_text:				"Lokal kanalfarge",
						modal_inheritcolor_text:				"Arve farge til underkanaler"
					};
				case "pl":		//polish
					return {
						context_localchannelsettings_text:		"Lokalne ustawienia kanału",
						submenu_channelsettings_text:			"Zmień ustawienia",
						submenu_resetsettings_text:				"Resetuj ustawienia",
						modal_header_text:						"Lokalne ustawienia kanału",
						modal_channelname_text:					"Lokalna nazwa kanału",
						modal_colorpicker1_text:				"Lokalny kolor kanału",
						modal_inheritcolor_text:				"Dziedzicz kolor do podkanałów"
					};
				case "pt-BR":	//portuguese (brazil)
					return {
						context_localchannelsettings_text:		"Configurações local do canal",
						submenu_channelsettings_text:			"Mudar configurações",
						submenu_resetsettings_text:				"Redefinir canal",
						modal_header_text:						"Configurações local do canal",
						modal_channelname_text:					"Nome local do canal",
						modal_colorpicker1_text:				"Cor local do canal",
						modal_inheritcolor_text:				"Herdar cor aos sub-canais"
					};
				case "fi":		//finnish
					return {
						context_localchannelsettings_text:		"Paikallinen kanavan asetukset",
						submenu_channelsettings_text:			"Vaihda asetuksia",
						submenu_resetsettings_text:				"Nollaa kanava",
						modal_header_text:						"Paikallinen kanavan asetukset",
						modal_channelname_text:					"Paikallinen kanavanimi",
						modal_colorpicker1_text:				"Paikallinen kanavanväri",
						modal_inheritcolor_text:				"Hävitä väri alikanaville"
					};
				case "sv":		//swedish
					return {
						context_localchannelsettings_text:		"Lokal kanalinställningar",
						submenu_channelsettings_text:			"Ändra inställningar",
						submenu_resetsettings_text:				"Återställ kanal",
						modal_header_text:						"Lokal kanalinställningar",
						modal_channelname_text:					"Lokalt kanalnamn",
						modal_colorpicker1_text:				"Lokal kanalfärg",
						modal_inheritcolor_text:				"Inherit färg till subkanaler"
					};
				case "tr":		//turkish
					return {
						context_localchannelsettings_text:		"Yerel Kanal Ayarları",
						submenu_channelsettings_text:			"Ayarları Değiştir",
						submenu_resetsettings_text:				"Kanal Sıfırla",
						modal_header_text:						"Yerel Kanal Ayarları",
						modal_channelname_text:					"Yerel Kanal Adı",
						modal_colorpicker1_text:				"Yerel Kanal Rengi",
						modal_inheritcolor_text:				"Renkleri alt kanallara miras alma"
					};
				case "cs":		//czech
					return {
						context_localchannelsettings_text:		"Místní nastavení kanálu",
						submenu_channelsettings_text:			"Změnit nastavení",
						submenu_resetsettings_text:				"Obnovit kanál",
						modal_header_text:						"Místní nastavení kanálu",
						modal_channelname_text:					"Místní název kanálu",
						modal_colorpicker1_text:				"Místní barvy kanálu",
						modal_inheritcolor_text:				"Zdědit barvu na subkanály"
					};
				case "bg":		//bulgarian
					return {
						context_localchannelsettings_text:		"Настройки за локални канали",
						submenu_channelsettings_text:			"Промяна на настройките",
						submenu_resetsettings_text:				"Възстановяване на канал",
						modal_header_text:						"Настройки за локални канали",
						modal_channelname_text:					"Локално име на канал",
						modal_colorpicker1_text:				"Локален цветен канал",
						modal_inheritcolor_text:				"Наследи цвета до подканали"
					};
				case "ru":		//russian
					return {
						context_localchannelsettings_text:		"Настройки локального канала",
						submenu_channelsettings_text:			"Изменить настройки",
						submenu_resetsettings_text:				"Сбросить канал",
						modal_header_text:						"Настройки локального канала",
						modal_channelname_text:					"Имя локального канала",
						modal_colorpicker1_text:				"Цвет локального канала",
						modal_inheritcolor_text:				"Наследовать цвет на подканалы"
					};
				case "uk":		//ukrainian
					return {
						context_localchannelsettings_text:		"Налаштування локального каналу",
						submenu_channelsettings_text:			"Змінити налаштування",
						submenu_resetsettings_text:				"Скидання каналу",
						modal_header_text:						"Налаштування локального каналу",
						modal_channelname_text:					"Локальне ім'я каналу",
						modal_colorpicker1_text:				"Колір місцевого каналу",
						modal_inheritcolor_text:				"Успадковують колір до підканалів"
					};
				case "ja":		//japanese
					return {
						context_localchannelsettings_text:		"ローカルチャネル設定",
						submenu_channelsettings_text:			"設定を変更する",
						submenu_resetsettings_text:				"チャネルをリセットする",
						modal_header_text:						"ローカルチャネル設定",
						modal_channelname_text:					"ローカルチャネル名",
						modal_colorpicker1_text:				"ローカルチャネルの色",
						modal_inheritcolor_text:				"サブチャンネルに色を継承"
					};
				case "zh-TW":	//chinese (traditional)
					return {
						context_localchannelsettings_text:		"本地頻道設置",
						submenu_channelsettings_text:			"更改設置",
						submenu_resetsettings_text:				"重置通道",
						modal_header_text:						"本地頻道設置",
						modal_channelname_text:					"本地頻道名稱",
						modal_colorpicker1_text:				"本地頻道顏色",
						modal_inheritcolor_text:				"繼承子通道的顏色"
					};
				case "ko":		//korean
					return {
						context_localchannelsettings_text:		"로컬 채널 설정",
						submenu_channelsettings_text:			"설정 변경",
						submenu_resetsettings_text:				"채널 재설정",
						modal_header_text:						"로컬 채널 설정",
						modal_channelname_text:					"로컬 채널 이름",
						modal_colorpicker1_text:				"지역 채널 색깔",
						modal_inheritcolor_text:				"하위 채널에 색상 상속"
					};
				default:		//default: english
					return {
						context_localchannelsettings_text:		"Local Channelsettings",
						submenu_channelsettings_text:			"Change Settings",
						submenu_resetsettings_text:				"Reset Channel",
						modal_header_text:						"Local Channelsettings",
						modal_channelname_text:					"Local Channelname",
						modal_colorpicker1_text:				"Local Channelcolor",
						modal_inheritcolor_text:				"Inherit color to Sub-Channels"
					};
			}
		}
	}
})();