-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedditTextSpoilers.js
53 lines (47 loc) · 1.96 KB
/
RedditTextSpoilers.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
// ==UserScript==
// @name Auto Click Shreddit Spoilers (Reddit Text Spoiler Clicker)
// @namespace https://raw.githubusercontent.com/zellchristensen/UserScripts/main/RedditTextSpoilers.js
// @downloadURL https://raw.githubusercontent.com/zellchristensen/UserScripts/main/RedditTextSpoilers.js
// @updateURL https://raw.githubusercontent.com/zellchristensen/UserScripts/main/RedditTextSpoilers.js
// @version 2024-10-05_1.0
// @description Automatically clicks all <shreddit-spoiler> elements on the page after it loads.
// @author Zell
// @match https://www.reddit.com/*
// @icon https://www.redditstatic.com/shreddit/assets/favicon/192x192.png
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to click all the spoiler elements
function revealSpoilers() {
// Get all "shreddit-spoiler" elements
const spoilers = document.querySelectorAll('shreddit-spoiler');
// Iterate over each spoiler element
spoilers.forEach(spoiler => {
// Find the button inside the shadow DOM
const shadowRoot = spoiler.shadowRoot;
if (shadowRoot) {
const button = shadowRoot.querySelector('.outer');
if (button) {
button.click(); // Click the button to reveal the spoiler
}
}
});
}
// Run the function to reveal spoilers
revealSpoilers();
// Optionally, you can set a MutationObserver to detect new spoilers added to the page
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
revealSpoilers(); // Call the function to reveal any new spoilers
}
});
});
// Start observing for changes in the body
observer.observe(document.body, {
childList: true,
subtree: true
});
})();