Daddy Clanger ([info]imc) wrote,
@ 2008-05-23 12:54:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:computers, lj

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

  • 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.


(22 comments) - (Post a new comment)


[info]frayer
2008-05-23 12:53 pm UTC (link)
Election campaign: You has it. :D :D :D

(Reply to this)


[info]7rin
2008-05-23 02:12 pm UTC (link)
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. ;)

(Reply to this) (Thread)


[info]imc
2008-05-23 02:22 pm UTC (link)
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? :-)

(Reply to this) (Parent)(Thread)


[info]bopeepsheep
2008-05-31 09:45 pm UTC (link)
I use SeaMonkey. So you definitely aren't the only nutter...

(Reply to this) (Parent)

In opera...
[info]pizza.maircrosoft.com
2008-05-23 09:07 pm UTC (link)
... 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?)

(Reply to this) (Thread)

Re: In opera...
[info]imc
2009-05-05 03:11 pm UTC (link)
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. ;-)

(Reply to this) (Parent)(Thread)

Re: In opera...
[info]msree
2009-05-07 01:43 am UTC (link)
There's one line that trips up Opera, otherwise it works nicely. It's this one:
if (info == undefined) return;

I changed return to exit and it works great, no JavaScript errors, even on Dreamwidth! It does need the gmfunctions helper script, like most scripts that weren't written especially for Opera.

Thank you so much!

(Reply to this) (Parent)(Thread)

Re: In opera...
[info]blandinavian
2009-11-13 04:35 pm UTC (link)
Okay, so way late, but I just wanted to say thanks for posting this comment! Couldn't get it to work even after the gmfunctions-file I found somewhere else, but return -> exit, and it works like a charm!

Now if only Opera would be a bit quicker at this whole thing and not fail when the site gets too long... But it's not like I'll switch browser anyways, they've got me hooked.

(Reply to this) (Parent)


[info]weaverandom
2009-04-25 07:20 am UTC (link)
This looks awesome! Does it work on JournalFen and/or Dreamwidth etc?

(Reply to this) (Thread)


[info]weaverandom
2009-04-25 07:20 am UTC (link)
(obviously, I mean if one adds JournalFen.Net etc to the list of sites to apply it to.)

(Reply to this) (Parent)(Thread)


[info]imc
2009-04-26 12:43 am UTC (link)
I have no idea whether it works… why not try it and see?

It depends on how much those other sites have tinkered with the comment-displaying code and what their styles are like. I don't know, since I don't have accounts on those sites (and of course Dreamwidth wasn't a reality at the time when I posted this code).

(Reply to this) (Parent)(Thread)


[info]nostariel
2009-05-03 07:04 am UTC (link)
Sadly, it does not seem to work. Which suuuucks, as I don't yet have a paid account over there.

ETA: Works on the ?format=light pages, w00t!

ETA 2: Also on site-style pages, yay!

Now if it only worked one the custom comments pages, which all the styles seem to default to...

Edited at 2009-05-03 08:01 am UTC

(Reply to this) (Parent)(Thread)


[info]imc
2009-05-05 03:07 pm UTC (link)
I've updated the script to cope with the style found here:

http://dw-news.dreamwidth.org/5921.html

(in the assumption that that's DW's default style). The "Expand all" link should appear just below the "Leave a comment" link at the bottom of the main journal entry (and also at the bottom of everything).

(Reply to this) (Parent)(Thread)


[info]nostariel
2009-05-07 12:26 am UTC (link)
Yes! *hands you internets*

That's the Transmogrified style and custom comment pages you're seeing on the News comm there. It is also, thankfully, the most popular style on Dreamwidth, so this is very helpful. Right now they only have 3 styles to choose from: that one, Negatives, and Zesty. Transmogrified is the least fug, so everyone is using it.

Would you like your internets wrapped in sparkle ponies or a Dreamwidth invite code?

(Reply to this) (Parent)


[info]imc
2009-05-05 03:13 pm UTC (link)
It now does work on at least some DreamWidth pages (tested on dw_news).

(Reply to this) (Parent)


[info]rina1do
2009-05-04 04:31 pm UTC (link)
Great Script! Thank you!

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

(Reply to this) (Thread)


[info]imc
2009-05-05 03:09 pm UTC (link)
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.

(Reply to this) (Parent)


[info]solarpowerspork
2009-07-08 04:03 pm UTC (link)
I tried this on Safari. Doesn't work. So there's your data ;).

(Reply to this)


[info]tavella
2009-08-22 09:15 pm UTC (link)
Oh, thank you! My old unfold all addons had stopped working.

(Reply to this)


[info]captainmarveljt
2009-11-24 06:19 am UTC (link)
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.

(Reply to this) (Thread)


[info]imc
2009-11-30 04:53 pm UTC (link)
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).

(Reply to this) (Parent)


[info]legolegs
2009-11-30 05:27 pm UTC (link)
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

(Reply to this)


(22 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…