Paul Wright (pw201) wrote,
  • Music: This Girl - T'Pau

Monkeying around

I've finally got around to writing the Greasemonkey script which I've long been threatening.

What it does

The script remembers which comments you've seen on LJ (or Dreamwidth) and helps you navigate to new comments. That's right, I'm finally dragging LiveJournal kicking and screaming into the 1980s.

If you're on an entry page, pressing "n" skips you to the next new comment, and "p" skips to the previous one. If the style has an "Expand" link, moving to an unexpanded comment with these keys will also expand the thread. If the style has a permanent link or a reply link for each comment in that comment's header or footer, the script inserts another link next to it, labelled "NEW". That link shows you that the comment is new at a glance. Clicking the "NEW" link selects the comment so that pressing "n" will go to the next comment from there. On some styles, the currently selected comment will be outlined with a dotted line.

On a journal or friends page, the script will also add the number of new comments to the link text, so that, say, "15 comments" becomes "15 comments (10 new)", and enable the "n" and "p" keys to move between entries which have new comments, and the "Enter" key to view the selected entry. This only works if you're looking at a journal which adds "nc=N" to entry links to say there are N comments on an entry (LJ can do this as a trick to confuse your browser's history function into thinking you've not visited that entry whenever there are new comments). If you want to turn this on for your journal then ensure you're logged in, visit this page, check the box which says "Add &nc=xx to comment URLs" and hit the "Save" button.

How it works

You don't need to understand this section to use the script. If you don't care about programming, skip to the next part.

LJ makes it a total pig to do this sort of thing: there's so little uniformity in journal styles that getting a script like this to work for all of them is impossible. It's fair enough that LJ allows people to customise their journal's appearance, but there aren't even standardised CSS class names for stuff. Not that I'm bitter. So, what the script does is look for anchor tags of the form <a name="tNNNN"> or elements with an id attribute of ljcmtNNNN or tNNNN. NNNN is the comment number, which seems to be unique for each comment on a given user's journal. It then looks for the permanent link to that comment, which is usually to be found in the header of the comment (or footer, in my current style), and adds a "New" link after that. So, new comments are marked with a link to the next new comment.

The upshot of all this is that if you're reading a journal with a style which doesn't use either anchor tags or elements with the given id for all comments, the script won't work correctly. If the style doesn't provide each comment with a permanent link in the comment's header, the comment won't be marked with a "New" link. Such is life. Please don't ask me for special case changes to make it work with LJ's many horribly customised journals. Pick a sensible style of your own and learn to use "style=mine" instead. There's even another Greasemonkey userscript which will help. On the other hand, if there's a large class of the standard styles for which it doesn't work, tell me and I'll have a look at it.

Using it

If you want to use it, you will need:

  • Firefox, the web browser, version 1.5 or later.
  • Greasemonkey, the extension which lets people write little bits of Javascript to run on certain pages.
  • LJ New Comments, which is what I've imaginatively entitled my script. If the userscripts site is down again, you can find a copy on my site.
  • Your flask of weak lemon drink.

After you've installed all of the above, visit an entry on LJ and marvel at the "NEW" links on all the new comments (which will be all of them at this point, as the script wasn't around previously to remember which ones you'd seen before). See above for operating instructions.

Privacy

Note that the script stores a Firefox preference key for each journal entry you visit, listing the IDs of the comments it finds there. The script doesn't let the database grow without limit: when the script has seen 500 entries, it starts to drop the history for the entries you've not visited recently.

Clearing the browser's history doesn't affect the script's list of visited entries. Thus your visits to polybdsmfurries will be recorded for posterity, even if you clear the browser's history. You can wipe the entire history by using the "Manage User Scripts" entry on the Tools menu to delete the script and its associated preferences (you can re-install it afterwards, but you must clear out the preferences for it to delete the history).

The script does not record the contents of any entry or comment. The script does not transmit any information to LJ or any other website, it merely acts on what it sees when you request journal entries.

Your questions

I've given this entry as the homepage for the script on Userscripts.org. That means this entry is intended to serve as a repository for questions about the script, so if you've got a question, comment here. I prefer this to commenting on my other entries or to emailing me, unless you already know me. Ta.

To keep up to date with new releases of my greasemonkey scripts, track the tag "greasemonkey" on my journal. This link should enable you to subscribe to that tag and get notified when I post a new entry about greasemonkey scripts.

Revision history

2006-01-02, version 0.1: First version.

2006-01-03, version 0.2: Added the "p" key. Used javascript to move between comments so doing so does not pollute the browser's history. Coped with the id=ljcmtNNNN way of marking comments. Made "n" and "p" keys work even in the absence of permalinks on each comment.

2006-01-04, version 0.3: Apparently you can have id=tNNNN, too.

2006-01-04, version 0.4: Broke 0.3, fixed it again. I hope.

2006-01-19, version 0.5: Updated to cope with LJ's new URL formats. Changed how comments are stored internally so that the database does not grow without limit: the script now remembers comments for the last 500 entries you visited, and forgets the entries you've visited least. Also added "New" marker based on reply link as well as thread link, for styles which don't have a thread link for every comment.

2006-01-19, version 0.6: Convert dashes I find in URLs to underscores internally, to preserve access to history from older versions of the script before LJ's URL change.

2006-02-09, version 0.7: Work around the fact that Firefox leaks memory like a sieve. Never display negative number of new comments. Change licence to MIT as GPL is overkill for this script.

2006-02-09, version 0.8: There was a bug in the workaround code I got off the Greasemonkey mailing list. Fixed that.

2006-06-04, version 0.9: Enabled the "n" and "p" keys on the friends/journal view. Added the box around the current comment.

2007-02-20, version 1.0, baby: Try harder to draw a box around the current new comment. Applied legolas's fix for pressing CTRL at same time as the N or P keys (see comments).

2008-03-31, version 1.1: Make it work faster on entries with lots of comments. Altered behaviour of "NEW" link so it now selects the comment you're clicking on, as that makes more sense.

2008-09-24, version 1.2: Support Russian keyboards thanks to mumische, make threads expand.

2009-01-27, version 1.3: Support for independentminds journals.

2009-05-04, version 1.4: Support for Dreamwidth.

2009-09-22, version 1.5: Amend support for Dreamwidth.

2010-08-09, version 1.6: Made syndicated journals work.

Tags: blog, computers, greasemonkey, livejournal, programming, tools
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded  

  • 83 comments