-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReddit_Comment_Expander.user.js
123 lines (107 loc) · 3.93 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
// ==UserScript==
// @name Expand All Reddit Replies (Toggleable)
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Toggleable auto-expand for "more replies" on Reddit posts with an improved 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;
function clickMoreRepliesButtons() {
if (!isExpanding) return;
const moreRepliesButtons = document.querySelectorAll(
'faceplate-partial[loading="action"][src*="/svc/shreddit/more-comments/"] > div > button[type="button"], a[id^="comments-permalink-"][slot="more-comments-permalink"]'
);
console.log("Found", moreRepliesButtons.length, "'more replies' buttons");
moreRepliesButtons.forEach(button => {
if (button.offsetParent !== null && !button.disabled) {
console.log("Clicking 'more replies' button...");
button.click();
}
});
}
function addStyle(css) {
const style = document.createElement('style');
style.textContent = css;
document.head.appendChild(style);
}
addStyle(`
faceplate-partial[loading="action"][src*="/svc/shreddit/more-comments/"] > div > button[type="button"],
a[id^="comments-permalink-"][slot="more-comments-permalink"] {
display: block !important;
visibility: visible !important;
pointer-events: auto !important;
}
#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;
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();
window.addEventListener('scroll', () => {
setTimeout(clickMoreRepliesButtons, 2000);
});
const commentsSection = document.querySelector('.ListingLayout-outerContainer');
if (commentsSection) {
const commentsObserver = new MutationObserver(clickMoreRepliesButtons);
commentsObserver.observe(commentsSection, { childList: true, subtree: true });
}
}
if (document.readyState === 'complete') {
initScript();
} else {
window.addEventListener('load', initScript);
}
setInterval(clickMoreRepliesButtons, 5000);
})();