The Pug Automatic

Preview images from within LiveJournal cuts

Written September 10, 2006. Tagged Greasemonkey, JavaScript, Firefox, LiveJournal.

LiveJournal is a sort of blogging community. I don't really participate in it myself, but my girlfriend does.

On LiveJournal, it is common to put long posts or large/plentiful/not-worksafe images behind a "LJ-cut", which means that the cut contents are not displayed in lists of posts, but only when you open the dedicated page for that post.


Some people want pretty much everything inside cuts; others want some content outside the cut to know whether they want to see more or not. My girlfriend is in the latter camp, and so I made a Greasemonkey script for cut image previews.

The script and usage instructions are over at

The script works with the LiveJournal S2 Generator layout style, and some other layout I encountered. The last time I wrote a complex script for LiveJournal, I put some effort into making it work across layouts – and even in Opera 9. I don't want to do that now – it is Somebody Else's Problem – but I've tried to make the code easy to adjust by someone who knows their way around JavaScript and XPath expressions.

Update 2007-05-11

Should now work in most layouts.

LJ-cut links are identified by the href containing "#cutid". I think this is constant across all layouts.

When retrieving images on a dedicated post page, the contents related to a particular cut are assumed to between <a name="cutidn"></a> and the next such tag, or else the end of the post contents as represented by <hr width='100%' size='2' align='center' />. This might or might not be constant across layouts – I couldn't find anything that broke the pattern, but perhaps the layout of dedicated post pages depends on the logged-in user.

The XPath expression stored in xpath_cut_to_post is used to find the post element (containing the post contents) relative to a cut link. This definitely varies across layouts, so it is probably the first place to look if things don't work. Finding the post element is not necessary if "Preview even if images precede cut" is toggled on.