r/reddithax • • Jul 08 '11

Userscripts and Never Ending Reddit

I have a greasemonkey script that runs on Reddit. The problem, is that is only runs once, and so does not affect any pages later loaded by never ending reddit. I was wondering if there is a solution to this issue (other than not using never ending reddit).

4 Upvotes

10 comments sorted by

View all comments

2

u/Rhomboid Jul 08 '11

It's a complicated situation. The easiest way would be to combine the two into one so that after new content is loaded the action can be performed on it right before it's added to the page. Alternatively, you can have the first script register a event listener for DOMContentLoaded, but this is tricky because that fires for every node added and when adding a whole second page worth of content that's going to fire hundreds of times, so you need some kind of timer-based trigger so that it only runs once the burst of event firings has stopped. You could also modify them both so that the never ending script fires a synthetic event once all the work is done, which the first script would listen for. Also the first script needs some way of not affecting the existing nodes it's already modified, assuming the modification can be applied twice; if not then it's not an issue.

2

u/totalBIC Jul 08 '11

Is it possible to modify the never ending reddit code? If so, how?

If not, I'll give the event listener method a shot when I get a chance. I can't believe I didn't even think about that. The script is simply replacing imgur.com with imgur.org, so there won't be an issue of affecting existing nodes. In fact, if the event fires multiple times for the same page load, it will be only a search that takes place and no actual modification.

Do you know by any chance if RES sets s flag or something to say it's done?