-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReddit_Comment_Expander.user.js
147 lines (120 loc) · 4.62 KB
/
Reddit_Comment_Expander.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
// ==UserScript==
// @name Expand All Reddit Replies (Toggleable)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Toggleable auto-expand for "more replies" on Reddit posts with a floating button
// @author Amir Tehrani
// @match https://www.reddit.com/r/*/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
console.log("Tampermonkey script loaded");
let isExpanding = false;
let hasMoreButtons = true; // Track if there are potentially more buttons
function clickMoreRepliesButtons() {
if (!isExpanding || !hasMoreButtons) return; // Stop if not expanding or no more buttons
const moreRepliesButtons = document.querySelectorAll(
'faceplate-partial[loading="action"][src*="/svc/shreddit/more-comments/"] > div > button[type="button"]'
);
if (moreRepliesButtons.length === 0) {
hasMoreButtons = false; // No buttons found, assume no more
console.log("No more 'expand in place' buttons found.");
return;
}
console.log("Found", moreRepliesButtons.length, "'expand in place' buttons");
moreRepliesButtons.forEach(button => {
if (button.offsetParent !== null && !button.disabled) {
console.log("Clicking 'expand in place' button...");
button.click();
}
});
}
function addStyle(css) {
const style = document.createElement('style');
style.textContent = css;
document.head.appendChild(style);
}
addStyle(`
#toggleExpandButton {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 9999;
padding: 10px 15px;
background-color: #f0f0f0;
color: #333;
border: none;
border-radius: 25px;
cursor: pointer;
font-family: Arial, sans-serif;
font-size: 14px;
font-weight: bold;
text-transform: uppercase;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
transition: all 0.3s ease;
outline: none;
}
#toggleExpandButton:hover {
background-color: #e0e0e0;
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
#toggleExpandButton:active {
transform: scale(0.95);
}
#toggleExpandButton.active {
background-color: #ff4500;
color: white;
}
#toggleExpandButton.active:hover {
background-color: #ff5722;
}
`);
function addToggleButton() {
const button = document.createElement('button');
button.id = 'toggleExpandButton';
button.textContent = 'Enable Auto-Expand';
button.addEventListener('click', toggleExpanding);
document.body.appendChild(button);
}
function toggleExpanding() {
isExpanding = !isExpanding;
hasMoreButtons = true; // Reset hasMoreButtons when toggling to enable again
const button = document.getElementById('toggleExpandButton');
button.textContent = isExpanding ? 'Disable Auto-Expand' : 'Enable Auto-Expand';
button.classList.toggle('active', isExpanding);
if (isExpanding) {
clickMoreRepliesButtons();
}
}
function initScript() {
addToggleButton();
const commentsSection = document.querySelector('.ListingLayout-outerContainer');
if (commentsSection) {
const commentsObserver = new MutationObserver(() => {
if(isExpanding){
clickMoreRepliesButtons();
}
});
commentsObserver.observe(commentsSection, { childList: true, subtree: true });
const moreCommentsButtonObserver = new MutationObserver(() => {
const viewMoreCommentsButton = document.querySelector('div.inline-block.mt-\\[2px\\].ml-px > faceplate-tracker > button');
if (viewMoreCommentsButton && isExpanding) {
console.log("'View more comments' button found, enabling hasMoreButtons.");
hasMoreButtons = true;
}
});
moreCommentsButtonObserver.observe(commentsSection, { childList: true, subtree: true });
}
window.addEventListener('scroll', () => {
setTimeout(clickMoreRepliesButtons, 2000);
});
}
if (document.readyState === 'complete') {
initScript();
} else {
window.addEventListener('load', initScript);
}
setInterval(clickMoreRepliesButtons, 5000);
})();