forked from v-qu/discord-channel-collapse-button
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
39 lines (36 loc) · 2.48 KB
/
main.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
(function(){
var ChannelCollapse = {
addToolbarItem: function() {
if(document.querySelectorAll('.show-channels-button').length == 0) {
var newToolbarItem = document.createElement('button');
newToolbarItem.type = 'button';
newToolbarItem.classList.add('show-channels-button');
newToolbarItem.classList.add('active');
newToolbarItem.innerHTML = '<span style="display: block; color: #fefefe; -webkit-transform: scale(2.0, 1.0); -moz-transform:scale(2.0, 1.0); -ms-transform:scale(2.0, 1.0); -o-transform:scale(2.0, 1.0); transform: scale(6,1); width: 0; height: 5px; text-align: center; position: absolute; top: 1px; left: 0;">-</span><span style="display: block; color: #fefefe; -webkit-transform: scale(2.0, 1.0); -moz-transform:scale(2.0, 1.0); -ms-transform:scale(2.0, 1.0); -o-transform:scale(2.0, 1.0); transform: scale(6,1); width: 0; height: 5px; position: absolute; top: 6px; left: 0;">-</span><span style="display: block; color: #fefefe; -webkit-transform: scale(2.0, 1.0); -moz-transform:scale(2.0, 1.0); -ms-transform:scale(2.0, 1.0); -o-transform:scale(2.0, 1.0); transform: scale(6,1); width: 0; height: 5px; position: absolute; top: 11px; left: 0;">-</span>';
document.querySelector('.header-toolbar').insertBefore(newToolbarItem,document.querySelector('.header-toolbar div.separator'));
document.querySelector('.show-channels-button').addEventListener('click',function(e){
if(this.classList.contains('active')) {
document.querySelector('.channels-wrap').style.display = 'none';
this.classList.toggle('active');
} else {
document.querySelector('.channels-wrap').style.display = 'flex';
this.classList.toggle('active');
}
});
}
},
addEventListeners: function(){
var guilds = document.querySelectorAll('.guild');
for(var i = 0;i < guilds.length; ++i) {
guilds[i].addEventListener('click',function(){
window.setTimeout(function(){
console.log("Added event listener");
ChannelCollapse.addToolbarItem();
},1);
});
}
}
};
ChannelCollapse.addToolbarItem();
ChannelCollapse.addEventListeners();
})();