-
Notifications
You must be signed in to change notification settings - Fork 0
/
whatsapp-main.user.js
247 lines (207 loc) · 7.61 KB
/
whatsapp-main.user.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
// ==UserScript==
// @name WhatsApp Hide Chat List
// @namespace http://tampermonkey.net/
// @version 0.5
// @license MIT
// @description Hide WhatsApp Web chat list
// @author Guilherme Franco (9uifranco)
// @match https://web.whatsapp.com/
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/js/all.min.js
// @downloadURL https://update.greasyfork.org/scripts/480773/WhatsApp%20Hide%20Chat%20List.user.js
// @updateURL https://update.greasyfork.org/scripts/480773/WhatsApp%20Hide%20Chat%20List.meta.js
// ==/UserScript==
(function () {
'use strict';
let overlayButton, customToolbar;
let hasInitialized = false;
let isElementHidden = false;
const hideThreshold = 40;
// Create toolbar
function createToolbar() {
let toolbar = document.createElement('div');
toolbar.innerHTML = `<nav id="customToolbar">
<button title="Blur Screen" id="overlayButton" class="eye"><i class="fas fa-eye-slash fa-xs"></i></button>
<a title="GitHub Repo" id="githubLink" href="https://github.com/9uifranco/whatsapp-hide-chat-list#whatsapp-hide-chat-list" target="_blank"><i class="fa-brands fa-github fa-xs"></i></a>
</nav>`;
document.body.insertBefore(toolbar, document.body.firstChild);
overlayButton = document.getElementById('overlayButton');
customToolbar = document.getElementById('customToolbar');
}
// Toggle overlay
function toggleOverlay() {
let overlay = document.getElementById('overlay') || createOverlay();
overlay.classList.toggle('visible');
let isOverlayVisible = overlay.classList.contains('visible');
overlayButton.innerHTML = isOverlayVisible ? '<i class="fas fa-eye fa-xs"></i>' : '<i class="fas fa-eye-slash fa-xs"></i>';
}
// Create and return the overlay
function createOverlay() {
let overlay = document.createElement('div');
overlay.id = 'overlay';
document.body.appendChild(overlay);
return overlay;
}
// Adjust toolbar position based on mouse movement
function adjustToolbarPosition(event) {
let mouseX = event.clientX;
if (mouseX > window.innerWidth - 20 || isMouseOver(customToolbar)) {
customToolbar.style.right = '0';
} else {
customToolbar.style.right = '-200px';
}
}
// Check if mouse is over the element or its children
function isMouseOver(element) {
return element.contains(event.target);
}
// Update chat list visibility
function updateChatListVisibility() {
const chatList = document.querySelector('div._aigs > div:nth-child(4)');
if (chatList) {
const headerElement = chatList.querySelector('header');
const sideElement = chatList.querySelector('#side');
const isMouseOverElement = isMouseOver(chatList);
if (!hasInitialized) {
chatList.style.display = 'flex';
chatList.style.flex = 'unset';
chatList.style.maxWidth = '300px';
chatList.style.width = '0%';
chatList.style.backgroundColor = '#111b21';
chatList.style.transition = 'width .5s ease-out 0s';
sideElement.style.opacity = '0';
sideElement.style.transition = 'opacity .5s ease-out 0s';
headerElement.style.opacity = '0';
headerElement.style.transition = 'all .5s ease-out 0s';
hasInitialized = true;
}
if (isMouseOverElement || event.clientX <= hideThreshold) {
// Show
chatList.style.width = '100%';
sideElement.style.opacity = '1';
headerElement.style.opacity = '1';
isElementHidden = false;
} else {
// Hide
chatList.style.width = '0%';
sideElement.style.opacity = '0';
headerElement.style.opacity = '0';
isElementHidden = true;
}
}
}
// Set up MutationObserver
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === 'childList') {
// If there are added nodes, update the element visibility
if (mutation.addedNodes.length > 0) {
updateChatListVisibility();
updateGalleryVisibility();
}
}
});
});
// Update gallery visibility
function updateGalleryVisibility() {
const gallery = document.querySelector("._alip");
if (gallery) {
gallery.style.height = '0';
const isMouseOverElement = isMouseOver(gallery);
if (isMouseOverElement || (event.clientY >= (document.body.scrollHeight - hideThreshold))) {
// Show
gallery.style.height = '6.25rem';
} else {
// Hide
gallery.style.height = '0';
}
}
}
// Start observing the document for changes
observer.observe(document.body, {
childList: true,
subtree: true
});
// Initialize the script
function init() {
console.log(`%c
.d888 d8b d8b
d88P" "88b Y8P
888 888
"Y8888888 888 888 888
888 888 888 888
888 888 888 888
d88P Y8b. X88 888
88888P" "Y8888P' 888 f r a n c o
github.com/9uifranco
`, "font-family:monospace; color: orange;");
createToolbar();
overlayButton.addEventListener('click', toggleOverlay);
document.addEventListener('mousemove', function (event) {
adjustToolbarPosition(event);
updateChatListVisibility(event);
updateGalleryVisibility(event);
});
document.addEventListener('mouseleave', updateChatListVisibility);
}
// Add styles
let styles = `
#customToolbar {
background-color: #333;
color: white;
padding: 10px;
position: fixed;
height: 100%;
width: 3rem;
right: -200px; /* initially hide to the right */
top: 0;
z-index: 9999999;
transition: right 0.3s ease;
display: flex;
flex-direction: column;
gap: .5rem;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
}
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: none;
z-index: 9999998;
backdrop-filter: blur(10px);
}
#overlay.visible {
display: block;
}
#overlayButton.eye {
font-size: 1.5rem;
background: none;
border: none;
cursor: pointer;
color: white;
}
#githubLink {
font-size: 1.5rem;
background: none;
border: none;
cursor: pointer;
color: white;
text-decoration: none;
}
.chat-list-hidden #side {
display: none !important;
}
.chat-list-hidden #main {
margin-left: 0 !important;
}
`;
let styleElement = document.createElement('style');
styleElement.textContent = styles;
document.head.appendChild(styleElement);
init();
})();