-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-expand-rooms.user.js
90 lines (69 loc) · 2.32 KB
/
auto-expand-rooms.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
// ==UserScript==
// @name Auto-expand Rooms
// @namespace https://github.com/AMiller42/Userscripts
// @version 1.1
// @description Automatically expand current rooms in SE Chat sidebar
// @author Aaron Miller
// @match https://chat.stackexchange.com/*
// @match https://chat.stackoverflow.com/*
// ==/UserScript==
(function() {
// Change this value to change the size of the room list.
// Do this if it is too big, or not big enough.
let roomListSize = 150;
let style = document.createElement("style");
// Add custom scrollbar for room list
style.innerHTML =
`#room-div {
max-height: ${roomListSize}px;
overflow: auto;
}
#room-div::-webkit-scrollbar {
width: 6px;
}
#room-div::-webkit-scrollbar-track {
background: transparent;
}
#room-div::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
#room-div::-webkit-scrollbar-thumb:hover {
background: #555;
}`;
// Prevent rooms from collapsing again
style.innerHTML += `
[class^="activity-"] {
display: block !important;
}
`;
document.head.appendChild(style);
function expandRooms() {
let rooms = document.getElementById("my-rooms");
// Remove the link to expand and collapse the room list
let more = rooms.parentNode.getElementsByClassName("more");
if (more.length != 0) {
Object.values(more).forEach(element => {
element.remove();
});
}
// Make all of the rooms display
for (let room of rooms.children) {
room.style.display = "block";
}
rooms.outerHTML = "<div id=\"room-div\">" + rooms.outerHTML + "</div>";
}
let loadScreen = document.getElementById("loading");
let loaded = false;
// Create an observer to tell when the chat is loaded
let loading = new MutationObserver((_, observer) => {
if (loadScreen.style.opacity < 0.001) {
if (!loaded) {
loaded = true;
setTimeout(expandRooms, 250);
observer.disconnect();
}
}
});
loading.observe(loadScreen, {attributes: true});
})();