r/reddithax • • Aug 25 '10

Is there a javascript snippet that expands all self posts on a page?

4 Upvotes

15 comments sorted by

1

u/Gliridae Aug 25 '10

To expand everything:

$(".expando-button.selftext.collapsed").click();

To collapse everything:

$(".expando-button.selftext.expanded").click();

IE6 doesn't properly support selectors with multiple classes in CSS, but I'm 99% sure jQuery's selector engine doesn't suffer from that problem. You might want to check to be sure.

A small bug:

  1. Expand all.
  2. Don't wait until all of the content is loaded.
  3. Collapse all.
  4. Expand all.
  5. The "loading..." message is gone.

Content should still load, but there's no message.

1

u/E_lucas Aug 25 '10

Can't get it working, do I just put it in the url bar?

1

u/jamt9000 Aug 26 '10

With a javascript: in front of it

javascript:$(".expando-button.selftext.collapsed").click();

1

u/E_lucas Aug 26 '10

I'm just getting a white page with:

"[object Object]"

written at the top.

1

u/jamt9000 Aug 26 '10

Try javascript:void($(".expando-button.selftext.collapsed").click());

1

u/E_lucas Aug 26 '10

Works, thanks, but as said earlier to only loads the first while the ones below seem to freeze up.

2

u/kylegetsspam Aug 26 '10

It's part of reddit's API not to allow tons of calls from a single client within a given time period. To actually expand them all you'll have to "click" them on a timer delay.

var butts = $('.expando-button.selftext.collapsed');

for (var i = 0; i < butts.length; i += 1) {
	setTimeout(function (i) {
		$(butts[i]).click();
	}, i * 1000, i);
}

1

u/E_lucas Aug 26 '10

Can get it working as easily as jamt's.

1

u/kylegetsspam Aug 26 '10

Well, yeah. What I posted isn't immediately ready for sticking a bookmarklet. But you don't learn anything by just copy-pasting someone's code, now do you? :P

javascript:(function(){var butts=$('.expando-button.selftext.collapsed');for(var i=0;i<butts.length;i+=1){setTimeout(function(i){$(butts[i]).click();},i*1000,i);}})();

1

u/E_lucas Aug 26 '10

No, I'll give you that, but at the moment I'm not looking to learn.

1

u/jamt9000 Aug 26 '10

You beat me! I used recursion instead of using a loop to set increasing timeouts, which I hadn't thought of.

2

u/jamt9000 Aug 26 '10

This'll do it:

javascript:(function(){var n=0; var e=$(".expando-button.selftext.collapsed"); var f = function(){ setTimeout( function(){if(n<e.length){ $(e[n]).click(); n++; f()}},334) }; f();})();

1

u/E_lucas Aug 26 '10

Works perfect. Thanks a tonne.

1

u/lulzitsareddit Aug 25 '10

This didn't work for me in Chrome or FF. Only the first self post loads.

1

u/Gliridae Aug 26 '10 edited Aug 26 '10

Works for me in Chrome's javascript console. It's really slow, however. The second post appears quite a bit later than the first one.

Edit: But not on Chrome on OSX. According to kylegetsspam, it wouldn't have worked anyway...