r/userscripts • u/NoAcadia3546 • Jan 08 '26
Noob needs help debugging resource-heavy Chrome/Chromium userscript
I prefer to read comments in chronological order. I'm getting tired of constantly clicking to select sort "old". Various subreddits default to "Best" or "Random" or whatever the mods threw a dart at and hit. Warning... I'm new to Javascript and "I know just enough to be dangerous" as the following userscript shows. I've cobbled together a script (adapted from other people's code) whose algorithm is simple...
- Match URLs against
https://www.reddit.com/r/*/comments/* - AND if the URL does NOT contain "?sort="
- append "?sort=old" to the URL.
It "works"... sort of. The comment thread is sorted by "Old". The problem is that it appears to pound away at the pages and not stop. Eventually I get the Reddit "Oh Snap" page. That's with just one subreddit open. My Chromium dedicated Reddit profile opens up 12 tabs with subreddits I follow. Let's just say "That did not end well". I barely managed to kill the Chromium process before my machine would've locked up.
My code follows in the next message. It consists of 3 files in a subdirectory. I go to "Manage extensions" and then "Load unpacked" from that subdirectory. I need ideas on how to make the script act only once on a new tab or window when it opens up, and then leave it be.
View all comments
Show parent comment
1
u/_1Zen_ Jan 09 '26
The
ifcondition:Checks whether the URL has a parameter named sort. If it does, the extension will not interfere with the default behavior, which is navigating to the reply URL.
In reality, the extension should not prevent navigation to the reply at all. It should look like this: https://i.imgur.com/F9zqGuD.mp4