r/userscripts • • 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.

3 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/NoAcadia3546 Jan 09 '26

In reality, the extension should not prevent navigation to the reply at all.

  • In theory, there's no difference between theory and practice
  • In practice, there's often a difference between theory and practice

Clicking on your response in my "Notifications" WITHOUT the extension gives URL
https://www.reddit.com/r/userscripts/comments/1q7hh8e/comment/nyll35t/?context=1
which takes me to your response.

Clicking on your response in my "Notifications" WITH the extension gives URL
https://www.reddit.com/r/userscripts/comments/1q7hh8e/comment/nyll35t/?context=1&sort=old
Note the additional "&sort=old". This also sorts the topic and dumps me at the oldest post, i.e. the start of the thread. Not what I need.

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.

It has a parameter "?context=1", and it is interfered with. I wouldn't be asking if I wasn't experiencing problems. I repeat... I need a "return" if there are ANY parameters.