Daddy Clanger ([info]imc) wrote,

Greasemonkey!

LiveJournal Thread Expander with Expand All

http://userscripts.org/scripts/show/27128

I've hacked up a Thread Expander script for Greasemonkey. It has only been tested on a small number of layouts, but it seems to work for me so please bang on it and report any breakages here.

For recent updates see below.

What does it do?

We've all encountered this behaviour before and been irritated by it: if a LiveJournal post has 50 or more comments on it, LiveJournal will start collapsing the threads so that the deepest comments are only visible as one-line summaries. If you click on one, it opens a separate page with just that subthread on it. This Greasemonkey script adds an "Expand" link which expands the thread in-place so that you can read the thread in its original context. In addition, you get an "Expand All" link at the top (and bottom) of the comments page.

How do I install it?

It is a Greasemonkey script. If you are using Firefox and don't have Greasemonkey installed then you must first download it. Then, when you visit the userscripts.org link above and press "Install this script" you should see a dialogue offering to install it.

The script has been extensively tested on Seamonkey 1.x and should therefore also work on Firefox 2.x. I am aware that there is a Greasemonkey for Internet Explorer, but it is unlikely to work on that. It may work on Safari and/or Opera — I have no information about those browsers so try it and see.

Doesn't LiveJournal offer this functionality now?

Yes, but only for paid users (or if you are viewing a paid journal). If the script detects Expand links already on the page, it won't add any more (unlike some of the other Greasemonkey scripts available). You also get the following benefits:
  • Open to all, not just paid users;
  • A very useful Expand All link, and
  • If you have JavaScript disabled then it will replace the non-working JavaScript actions on any existing Expand links so that you can still use them. Yes, I'm aware that I'm probably the only person in the world who browses with Greasemonkey enabled and JavaScript disabled…

Some points to note

The Expand All function tries hard to expand each thread only once, which means it is lightning fast compared to all previous attempts to implement an unfold-all feature. This does mean, however, that it might not succeed in opening all threads fully on the first click. Just click on it again if any collapsed threads remain after the first go. The advantage of doing it this way is that you don't unwittingly tie up your browser for hours if you try to expand a page that is very deeply nested with hundreds of comments.

Some parts of this script are layout-dependent and one bit of it also depends on the "Thread" links on the page being in English (however, this is only for adding an Expand link to the parent of a collapsed thread, so it only matters if you don't already have Expand links on the page and it should still successfully create the Expand links for collapsed comments). It is layout-dependent because it needs to know where to add the "Expand All" link at the top of the page and where to add an Expand link to the parent of a collapsed thread. It has been extensively tested on site-scheme comment pages; it has also been lightly tested on Expressive and Generator layouts. Other layouts can probably be added if you direct me to an example of said layout (although if it's one that uses images rather than text for the thread links on each comment then adding the word Expand might look slightly out of place).

If you are viewing LiveJournal from within a frameset then the script currently won't work for you (but you could try removing the first line of code to fix this if you felt up to it).

Background

In the beginning there was Tim Babych's LJ Thread Unfolder. This looks like it is still being maintained to some extent, but does not have an Unfold All option. That option was hacked in by Henrik N in LJ Thread Unfolder with Unfold all. However, Henrik's script broke when LiveJournal introduced its own thread expander — click on the Unfold link and the whole thread disappears. Meanwhile, LJ Thread Unfolder &mdash Unfold All, All layouts was a different variation on the original script, this time by MrMord, which still carried on working. The disadvantage of MrMord's variation is that it only unfolds a single comment each time you click on an Unfold link. I once rendered my browser unusable for 90 minutes by clicking on the Unfold All from this script on a particularly nasty thread in [info]news. My script returns in under a minute on that page, but this is due to the advantage of not attempting to expand every single comment: it still leaves quite long sections of the thread unexpanded on the first click, whereupon you can then decide whether it is worth expanding them further. The second click takes a slightly less impressive eight minutes and still leaves a few of the deepest threads collapsed.

Although this script borrows some ideas (and possibly a few lines of code) from its predecessors and also from LiveJournal's own thread expander, it is a complete rewrite from scratch.

Updates

  • 2010-06-30: LiveJournal made a small change that broke the script's JS-detection, meaning the script stopped working on browsers with JavaScript enabled — a small fix has been applied. Also changed one line that got left out of the previous Opera fixes.
  • 2009-05-05: Added dreamwidth.org to list of included sites and fixed the script to work on one of their styles (the one used for dw_news). Made a few fixes to try to make it more Opera-friendly.
Tags: computers, lj

  • Post a new comment

    Error

    Your reply will be screened

    Your IP address will be recorded 

  • 44 comments

[info]frayer

May 23 2008, 12:53:19 UTC 3 years ago

Election campaign: You has it. :D :D :D

[info]7rin

May 23 2008, 14:12:01 UTC 3 years ago

Don't know why, but I just can't take to GreaseMonkey, which means it's probably a good job I use LJA**O*s instead.

You did make me LOL with "probably the only person in the world who browses with Greasemonkey enabled and JavaScript disabled", but I suspect you're wrong - you can't be the only nutter in the world. ;)

[info]imc

May 23 2008, 14:22:20 UTC 3 years ago

Don't know why, but I just can't take to GreaseMonkey

Oh well. It demonstrates my LJ + Geek credentials though, no? ;-)

probably a good job I use LJA**O*s instead.

Um. What??

I know, it's probably a Firefox extension. I don't do Firefox extensions, because I use SeaMonkey — which brings me to…

you can't be the only nutter in the world.

Still sure? :-)

[info]pizza.maircrosoft.com

May 23 2008, 21:07:51 UTC 3 years ago

In opera...

... save as .user.js to clue opera in to greasemonkey notation
(in particular, make the js run after the page has finished loading)
... have user js which supplies GM_ functions for opera
(maybe only needed for the GM_log debugging)
... top-level 'return' is a syntax error, I replaced with 'exit'
... unsafeWindow is a greaseMonkey object, replace instances with 'window'

seems to be working now. Ace.

(can we have a 'collapse again' in V2?)

[info]imc

May 5 2009, 15:11:35 UTC 3 years ago

Re: In opera...

A year late, but I've tried to incorporate the above points in the current version of the script.

As for V2, I guess that's a long way off. ;-)

[info]msree

3 years ago

[info]weaverandom

April 25 2009, 07:20:10 UTC 3 years ago

This looks awesome! Does it work on JournalFen and/or Dreamwidth etc?

[info]weaverandom

April 25 2009, 07:20:39 UTC 3 years ago

(obviously, I mean if one adds JournalFen.Net etc to the list of sites to apply it to.)

[info]imc

3 years ago

[info]nostariel

3 years ago

[info]imc

3 years ago

[info]nostariel

3 years ago

[info]imc

3 years ago

[info]rina1do

May 4 2009, 16:31:11 UTC 3 years ago

Great Script! Thank you!

"Expand all" function unavaiable on some journals, maybe it depends of a style used.

[info]imc

May 5 2009, 15:09:38 UTC 3 years ago

It does depend on the style used. If you can give me examples of pages that don't work (they have to be publicly accessible, obviously) then when I have time I'll try to incorporate that style.

[info]solarpowerspork

July 8 2009, 16:03:37 UTC 2 years ago

I tried this on Safari. Doesn't work. So there's your data ;).

[info]tavella

August 22 2009, 21:15:34 UTC 2 years ago

Oh, thank you! My old unfold all addons had stopped working.

[info]captainmarveljt

November 24 2009, 06:19:31 UTC 2 years ago

If I wanna use this script on Opera, do I have to download the Greasemonkey script as well? Because it says that that script is for Firefox and I could only download it using Firefox.

[info]imc

November 30 2009, 16:53:37 UTC 2 years ago

You don't have to install Greasemonkey itself because that's a Firefox extension that Opera mostly has already; you do have to install a Greasemonkey compatibility script for Opera called gmfunctions (thanks to an above comment for this info — see the comment for a link to gmfunctions and also one change you have to make to my script to make it work, until I get round to uploading a fixed version).

[info]legolegs

November 30 2009, 17:27:37 UTC 2 years ago

Patch for opera (also you must install this):
--- userjs_off/LJ_Thread_Expander.js	2009-11-30 18:55:28.000000000 +0300
+++ userjs/LJ_Thread_Expander.js	2009-11-30 20:23:01.152321910 +0300
@@ -21,14 +21,24 @@
 // @include http://*.dreamwidth.org/*
 // ==/UserScript==
 
+/*
+  globals
+*/
+
+var myWindow;
+var info;
+var needIndent;
+var allExpand;
+
+function LJ_Thread_Expander_init()
+{
 /* Experimental feature: don't handle nested frames (e.g. the ads).
    However, this means you can't embed your journal in a frameset. */
-if (window != window.parent) exit;
+if (window != window.parent) return;
 
 /* unsafeWindow is a GreaseMonkey variable that gives you access to
    the document's original window object.  If it's not defined
    (Opera?) then try defaulting back to the original window. */
-var myWindow;
 if (typeof unsafeWindow == "undefined") myWindow = window;
 else myWindow = unsafeWindow;
 
@@ -38,14 +48,14 @@
 
 /* Need the "LJ_cmtinfo" meta-info from the original comment page */
 if (JSdisabled) myWindow.LJ_cmtinfo = getLJcmtinfo(document);
-var info = myWindow.LJ_cmtinfo;
+info = myWindow.LJ_cmtinfo;
 if (info == undefined) return;
 
 /* used later for copyIndent function */
-var needIndent=1;
+needIndent=1;
    
 /* First find out whether LiveJournal has put Expand links on */
-var allExpand = xpath("//a[contains(@onClick,'Expander')]");
+allExpand = xpath("//a[contains(@onClick,'Expander')]");
 
 /* If it has, fix them up - if not, create them */
 makeExpandLinks(info);
@@ -54,6 +64,9 @@
 if (allExpand.length) addExpandAll();
 
 /* That's all, except the function definitions... */
+}
+//LJ_Thread_Expander_init();
+document.addEventListener('load',LJ_Thread_Expander_init, false);
 
 /* getLJcmtinfo(context)
  * If JavaScript is disabled, this function searches through the

[info]stansult

December 11 2009, 23:22:24 UTC 2 years ago

tried that on Chrome - unfortunately doesn't work...
it adds (to developer's version of Chrome), but doesn't unfold anything
any plans for Chrome?

[info]stansult

December 11 2009, 23:23:00 UTC 2 years ago

btw (forgot to add), you don't need greasemonkey for developer's version of Chrome
it adds itself, and many scripts work fine

[info]imc

2 years ago

[info]stansult

2 years ago

[info]amblinwiseass

January 20 2010, 13:47:10 UTC 2 years ago

This is awesome. Thank you!

Yes, I'm aware that I'm probably the only person in the world who browses with Greasemonkey enabled and JavaScript disabled…

Now there's an intriguing thought.

[info]discopanda

March 6 2010, 15:05:22 UTC 2 years ago

Any chance of getting it to work with whatever layout [info]girlgeniuscomic uses in their entries?

[info]imc

March 30 2010, 14:53:21 UTC 2 years ago

Sorry, I'd meant to look at this but haven't got round to it yet. I think that journal's style is 3column; as far as I can tell it does have Expand links (presumably because it's a permanent account) but the script doesn't know where to place the Expand All link. Stylistically this should probably be a button rather than a text link.

[info]mandalaya

May 7 2010, 18:08:07 UTC 2 years ago

It works, yay! Thank you! I also didn't know about Greasemonkey, so now I have lots of learning curve to enjoy :) Any recommended favorite scripts?

[info]lilitu93

June 30 2010, 11:54:49 UTC 1 year ago

I've been using this script for ages now, but unfortunately it stopped working on LJ last night. There's no 'Expand all' even on default layouts, and unless I disable it, clicking Expand manually on paid accounts doesn't work (and no Expand buttons show up for free ones).

I've tried it on 2 different computers, both running Firefox 3.5.10 (I think it's the same version or very close to it) and running Mac OS 10.5.8 Leopard on Intel Macs.

I haven't changed anything on my side, and I've tried reinstalling the script to no avail. Perhaps LJ did something to break it?

[info]imc

June 30 2010, 13:38:05 UTC 1 year ago

Oh dear, that's unfortunate!

I think I've found out what the problem is and made a small fix, so try fetching a new copy.

Anonymous

July 6 2010, 12:38:46 UTC 1 year ago

"Expand all" link don't show: http://zlatorada.livejournal.com/338730.html

[info]carbonel

August 1 2010, 02:05:55 UTC 1 year ago

I just found this, and it's exactly what I need to read a monstrous (but entertaining) thread.

I installed Greasemonkey just fine. But when I went to install the script, the Install button at the top of the page refuses to do anything. It looks as if it's being depressed or clicked or whatever, but it just pops up again and doesn't do anything.

Any idea what the problem might be?

[info]imc

August 4 2010, 15:52:13 UTC 1 year ago

It sounds like Greasemonkey may not be active in your browser.

You should have restarted the browser after installing Greasemonkey, and you should then see a little monkey face in the status bar at the bottom right corner. Mousing over this should say "Greasemonkey is enabled", and right-clicking on it should give the Greasemonkey options menu. Left-clicking on it will turn it grey and disable Greasemonkey (click again to re-enable).

If that's all working, then clicking on Install on the web page for a Greasemonkey script should cause the Greasemonkey dialogue to appear. Otherwise… I'm not really sure what the problem is.

[info]archinella

August 15 2010, 01:37:03 UTC 1 year ago

You so totally rock. This is an awesome script, and it's incredibly easy to install and use. Thank you so much for creating this script and making it public!

[info]archinella

August 15 2010, 04:14:22 UTC 1 year ago

So, I've been trying to get something to work for the past while: taking a screenshot of the webpage I've performed the thread expansion on. The screen capture extension I'm using (Screen Capture Elite, although I had the same problem with the extension ScreenGrab) won't capture the page where I've clicked 'Expand All.' It'll work on the page before clicking 'Expand All' and on other currently opened tabs, but not on the page where I've used the thread expansion script.

Any ideas of what might be causing this?

[info]imc

August 15 2010, 21:15:12 UTC 1 year ago

I've downloaded the Screen Capture Elite extension and it still seems to work after I've done Expand All (although it Greeks most of the text in the comments whether I've expanded them or not — is that normal?).

However, one time when I did it, it took a few minutes on high CPU before the save dialogue appeared. I'm guessing that the more comments there are on the page the more work it has to do, and I think it has to redraw the current document into a canvas which will be saved as an image — which means that more complicated documents (with lots of expanded comments) take longer and use more memory. But I've no idea how the Screen Capture extension works really so I don't think I can be much help in getting it to work, I'm afraid.

[info]addingsomecolor

April 6 2011, 01:45:43 UTC 1 year ago

This doesn't seem to work on anonymous comments.

[info]imc

April 6 2011, 10:50:02 UTC 1 year ago

As far as I can tell, it does — have you got a link to a page where this doesn't work?

It seems that some LiveJournal styles display screened comments as collapsed comments from "anonymous". If the comment is screened rather than being truly anonymous then obviously expanding it won't work.

[info]otana

September 20 2011, 23:06:22 UTC 7 months ago

Any word on getting this up and running on Chrome? It's one of the few scripts I really miss.

[info]shutter

September 22 2011, 14:14:33 UTC 7 months ago

this doesn't seem to work on page 2+ of posts anymore, just the first page.
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…