-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
78 lines (66 loc) · 2.57 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
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
// main.js
// Function to append the toggle button
function appendToggleButton() {
var actionsDiv = document.querySelector('div#actions');
if (actionsDiv) {
var button = document.createElement('button');
button.textContent = 'Comments?';
button.addEventListener('click', toggleCommentSection);
actionsDiv.appendChild(button);
// button style
button.style.backgroundColor = '#272727';
button.style.color = '#EFEFEF';
button.style.fontWeight = 'bold';
button.style.border = 'none';
button.style.borderRadius = '18px';
button.style.padding = '8px 16px';
button.style.marginLeft = '8px';
button.style.cursor = 'pointer';
button.style.height = '36px';
// Hover effect
button.addEventListener('mouseover', function() {
button.style.backgroundColor = '#3F3F3F';
});
button.addEventListener('mouseout', function() {
button.style.backgroundColor = '#272727';
});
// Active effect
button.addEventListener('mousedown', function() {
button.style.backgroundColor = '#535353';
});
button.addEventListener('mouseup', function() {
button.style.backgroundColor = '#272727';
});
}
}
// Function to toggle the visibility of the comment section
function toggleCommentSection() {
var commentSection = document.querySelector('ytd-comments');
if (commentSection) {
if (commentSection.style.display === 'none') {
commentSection.style.display = 'block';
} else {
commentSection.style.display = 'none';
}
}
}
// Callback function for MutationObserver
function mutationCallback(mutationsList, observer) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
// Check if div#actions has been added
if (document.querySelector('div#actions')) {
// If div#actions is available, stop observing and append the toggle button
observer.disconnect();
appendToggleButton();
var commentSection = document.querySelector('ytd-comments');
commentSection.style.display = 'none';
break;
}
}
}
}
// Create a MutationObserver to observe changes in the DOM
const observer = new MutationObserver(mutationCallback);
// Start observing the document for changes in the subtree
observer.observe(document, { subtree: true, childList: true });