This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
HideSidebar.plugin.js
113 lines (102 loc) · 3.81 KB
/
HideSidebar.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
/**
* @name HideSideBar
* @version 1.1.5
* @description Plugin to hide sidebar in discord
* @author Pieloaf
* @authorId 439364864763363363
* @website https://pieloaf.github.io
* @source https://github.com/Pieloaf/BetterDiscordPlugins/blob/main/HideSidebar.plugin.js
* @updateUrl https://raw.githubusercontent.com/Pieloaf/BetterDiscordPlugins/main/HideSidebar.plugin.js
*/
module.exports = (_ => {
function createSelector(className) {
return '.' + className.replace(/ /g, '.')
}
const sidebarSelector = createSelector(
//BdApi.findAllModules(m => m.sidebar)[1].sidebar
document.querySelector('[class^="sidebar"]').className
);
const guildBarSelector = createSelector(
document.querySelector('nav[class*="guilds-"').className
);
const sidebarBtn = document.createElement('span');
const btnStyle = `
.hide-sidebar-btn {
color: var(--interactive-normal);
background-color: var(--background-primary);
transition: background-color .15s ease-out,color .15s ease-out, border-radius .15s ease-out;
display: flex;
justify-content: center;
margin: 6px 10px;
padding: 5px 3px;
border-radius: 15px;
font-weight: 500;
}
.hide-sidebar-btn:hover{
border-radius: 7px;
cursor: pointer;
color: #fff;
background-color: var(--brand-experiment);
}`;
const toggleView = (sidebar) => {
if (
sidebar.style.display === "" ||
sidebar.style.display === "flex"
) {
sidebar.style.display = "none";
sidebarBtn.innerHTML = ">>>";
} else {
sidebar.style.display = "flex";
sidebarBtn.innerHTML = "<<<";
}
}
document.onkeydown = function (evt) {
let alt = evt.altKey;
let hKey = evt.key.toLowerCase() === "h";
if (alt && hKey)
toggleView(document.querySelector(sidebarSelector));
};
return class {
start() {
BdApi.injectCSS('HideSidebarStyles', btnStyle)
this.initialise()
}
stop() {
BdApi.clearCSS('HideSidebarStyles')
this.cleanup()
}
cleanup() {
sidebarBtn.remove()
}
createButton() {
const sidebar = document.querySelector(sidebarSelector)
sidebarBtn.innerHTML = '<<<'
sidebarBtn.classList.add('hide-sidebar-btn')
sidebarBtn.addEventListener('click', ()=>{toggleView(sidebar)})
return sidebarBtn
}
observer(mutationRecord) {
const serverList = document.querySelector(guildBarSelector).firstChild.childNodes[1]
const serverListSelector = createSelector(serverList.classList.value)
if (mutationRecord.type !== 'childList') return;
if (!mutationRecord.addedNodes.length) return;
for (const node of Array.from(mutationRecord.addedNodes)) {
if (node.matches && node.matches(serverListSelector)) {
this.initialise(node);
return;
} else if (node.querySelector) {
const child = node.querySelector(serverListSelector);
if (child) {
this.initialise(child);
return;
}
}
}
}
initialise(serverListNode) {
this.createButton()
let serverList = serverListNode || document.querySelector(guildBarSelector).firstChild.childNodes[1]
serverList.insertBefore(sidebarBtn, serverList.firstElementChild.nextSibling);
}
}
})();