-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitch-chat-username-filter.js
95 lines (84 loc) · 4.03 KB
/
twitch-chat-username-filter.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
let convict_username = '';
// we will scroll back to this position after removing the filter
let userMessagePosition;
const targetNode = document.querySelector('[data-test-selector="chat-scrollable-area__message-container"]');
// popup window can suck my big black cock
document.body.querySelector('[data-a-target="chat-user-card"]').style.setProperty('right', '100px');
document.body.querySelector('[data-a-target="chat-user-card"]').style.setProperty('top', '80px');
document.body.querySelector('[data-a-target="chat-user-card"]').style.setProperty('width', '60%', 'important');
const config = { attributes: true, childList: true, subtree: true };
const callback = function(mutationsList, observer) {
// Use traditional 'for loops' for IE 11
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
for (const asd of mutation.addedNodes) {
// @@@try other querySelectors
if (!asd.querySelector(`[data-a-user="${convict_username}"]`)) {
asd.style.display = 'none';
}
}
}
}
};
const observer = new MutationObserver(callback);
const filterButton = document.createElement("button");
filterButton.setAttribute('data-test-selector', 'username-filter-button');
filterButton.style.backgroundColor = "#f9f900";
filterButton.style.fontWeight = "600";
filterButton.style.padding = "0px 10px";
filterButton.style.borderRadius = "0.4rem";
filterButton.style.height = "3rem";
filterButton.style.alignSelf = "auto";
filterButton.style.color = "#262626";
filterButton.onclick = () => {
observer.disconnect();
filterButton.remove();
// document.body.querySelector('[data-test-selector="username-filter-button"]').remove();
const allChatLineMessages = targetNode.querySelectorAll('[data-test-selector="chat-line-message"]');
for (const element of allChatLineMessages) {
// if there is style attribute in tag = we fucked.
// use removeProperty("display") instead? but removing whole attribute should be faster, no?
element.removeAttribute('style');
}
document.getElementsByClassName("simplebar-scroll-content")[0].scrollTo({top: userMessagePosition, behavior: "auto"});
return;
}
filterButton.onmouseover = () => {
filterButton.style.backgroundColor = "#e7e700";
}
filterButton.onmouseout = () => {
filterButton.style.backgroundColor = "#f9f900";
}
function addRemoveFilterButton(e) {
const chatContainer = document.body.querySelector('[data-test-selector="chat-input-buttons-container"]');
const pointsButton = document.body.querySelector('[data-test-selector="community-points-summary"]');
filterButton.textContent = `Remove filter for @${convict_username}`;
if (pointsButton) {
pointsButton.append(filterButton);
} else {
chatContainer.prepend(filterButton);
}
// remove text selection, because the nickname is not a <button> but a <span>
document.getSelection().removeAllRanges()
return;
}
function userMessagesFilterHandler(event) {
// @@@ fix for single click or double click
if (event.target.dataset.testSelector === "message-username") {
userMessagePosition = document.getElementsByClassName("simplebar-scroll-content")[0].scrollTop;
observer.observe(targetNode, config);
convict_username = event.target.dataset.aUser;
for (let element of targetNode.querySelectorAll('[data-test-selector="chat-line-message"]')) {
if (!element.querySelector(`[data-a-user="${convict_username}"]`)) {
element.style.display = 'none';
}
}
for (let element of targetNode.querySelectorAll('[data-test-selector="user-notice-line"]')) {
if (!element.querySelector(`[data-a-user="${convict_username}"]`)) {
element.style.display = 'none';
}
}
addRemoveFilterButton();
}
}
targetNode.addEventListener('dblclick', userMessagesFilterHandler);