Last active
September 5, 2025 13:10
-
-
Save AniruddhaHumane/4f4cf4a2eea786cbb5bb488034c40713 to your computer and use it in GitHub Desktop.
Hide communities on page load on Reddit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use https://chromewebstore.google.com/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld | |
| // copy and paste this in JS section | |
| // Make sure you turn on on page load on bottom right | |
| document.addEventListener('DOMContentLoaded', () => { | |
| // Define the selector for the element we are looking for. | |
| const selector = '[aria-controls="communities_section"]'; | |
| // Define the interval in milliseconds (200ms = 0.2s). | |
| const checkInterval = 200; | |
| // Use setInterval to repeatedly check for the element. | |
| const intervalId = setInterval(() => { | |
| const element = document.querySelector(selector); | |
| // Check if the element was found. | |
| if (element) { | |
| // Set the aria-expanded attribute to false. | |
| element.setAttribute('aria-expanded', 'false'); | |
| console.log('Found element and set aria-expanded to false.'); | |
| // Find the closest parent <details> tag and remove the open attribute. | |
| const parentDetails = element.closest('details'); | |
| if (parentDetails) { | |
| parentDetails.removeAttribute('open'); | |
| console.log('Removed open attribute from the parent <details> tag.'); | |
| } | |
| // Stop the interval once the element is found to prevent it from running forever. | |
| clearInterval(intervalId); | |
| } | |
| }, checkInterval); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment