Is there a way to jump from one comment to the next using my keyboard? March 28, 2006 12:23 PM   Subscribe

Is there a way to jump from one comment (anchor) to the next using my keyboard? I like a feature in Bloglines where you can simply press "j" to go to the next article in a feed ("k" goes to the previous article). It would be nice if we had a navigation system similar to this going from comment to comment for MeFi/AskMe/MeTa threads.
posted by pithy comment to Feature Requests at 12:23 PM (64 comments total)

(I don't really like just pressing the down arrow.)
posted by pithy comment at 12:23 PM on March 28, 2006


GreaseMonkey is well-suited to this kind of thing.
posted by matthewr at 12:26 PM on March 28, 2006


Any suggested greasemonkey scripts? MeFi Navigator helps go from one person's comment to their next, but I don't think it helps go on from comment to comment.
posted by pithy comment at 12:30 PM on March 28, 2006


Yeah, I was just humming and hahhing about updating MeFi Navigator and adding something like this. (Any more feature suggestions, BTW?)

I think GreaseMonkey allows you to create preferences in Firefox, so users could map whichever keys they wanted to the back/forward commands.
posted by matthewr at 12:35 PM on March 28, 2006


(ah, now I see that you made MeFi Navigator, matthewr - Thanks!) So far I can't htink of other features to add.
posted by pithy comment at 12:42 PM on March 28, 2006


Thank goodness that's settled. There's been furious debate before about web-hotkeys superseding client-system hotkeys.

Superseding client-system hotkeys is bad.
posted by loquacious at 12:57 PM on March 28, 2006


but there usually isn't a client-system hotkey for a single keystroke.

I love this feature in reblog, lemme see how I can clone it.
posted by mathowie (staff) at 1:00 PM on March 28, 2006


Programs like Winamp use a lot of single-stroke hotkeys, but I digress and pick nits. But there's probably other programs.

I miss the autofind-link-while-typing feature in earlier mozilla/firefox. I assume there's a way to turn this back on that I haven't bothered to go track down. (heh, that's odd. I can't remember what animal name pre-firefox firefox was called.)

But I'll agree that less mousing and keyboard-reaching is good. I still fully intend to find a suitable enhanced keyboard that includes an IBM nipple-mouse, or hack the one I already have.
posted by loquacious at 1:09 PM on March 28, 2006


Loquacious: It's in Tools > Options > Advanced - the "Begin finding when you begin typing" checkbox. Firefox was Firebird, and before that Phoenix.
posted by matthewr at 1:13 PM on March 28, 2006


Programs like Winamp use a lot of single-stroke hotkeys

Yeah, but are they system-wide? In other words, you're using firefox, hit N to go to the next comment, and suddenly the music changes? Because if I was typing in text areas online all day, that would get old.
posted by mathowie (staff) at 1:14 PM on March 28, 2006


Thanks, matthewr.

Mathowie, true.

There was a debate somewhere either here in the grey or in the green about the hotkey issue before, and there were some valid points about it and some sort of conflict.

Though, it would probably be trivial to have an option in the preferences page to turn it on and off.
posted by loquacious at 1:17 PM on March 28, 2006


There was a debate somewhere either here in the grey or in the green about the hotkey issue before

Was that the one arguing for and against Alt-foo keystrokes to navigate between major sections of the site?
posted by cortex at 1:20 PM on March 28, 2006


Gah, I feel like such a n00b!

Sure, I can integrate Linux and Windows in a multi-machine, multi-monitor desktop configuration and I can support and use various Windows Server 2003 Active Directory hoo-hahs but I can't be bothered to look at the second item in the advanced preferences pane in Firefox!

I've been missing that feature probably over a year. *sigh*
posted by loquacious at 1:20 PM on March 28, 2006


Cortex: I think that was it. Single keystroke hotkeys probably renders it moot, then.
posted by loquacious at 1:21 PM on March 28, 2006


Hmm, I just tried adding this to Mefi Navigator, and it's not quite as easy as I had hoped. The trouble is, my script currently builds a multidimensional array of comments (not the whole comment, just what it needs i.e. author and permalink). This is ordered by author, not chronologically. Therefore, it's not completely trivial to work out the permalink of the next comment.

So in conclusion: the basic functionality of backward/forward keypresses is straightforward to implement on its own, but it's not easy to integrate it into the existing Mefi Navigator code. Matt adding a site-wide script sounds like a good plan (if he's keen), and would have the advantage of not being limited to Firefox+GM users.
posted by matthewr at 1:31 PM on March 28, 2006


I'd give a nut for this functionality. Especially if it was mapped to j/k. Pretty please...
posted by blag at 1:57 PM on March 28, 2006


So matthewr, how would I go about doing this? I could give every div an id of the comment number. Then some js could just watch for keystrokes and jump to the next higher id, right?

I can't seem to find any demo scripts of this on google, and the reblog code is pretty confusing to read.
posted by mathowie (staff) at 2:43 PM on March 28, 2006


Why don't you just select the first username link, and then hit tab three times

Hit tab three additional times to go to the next comment, and so on.
posted by delmoi at 3:04 PM on March 28, 2006


Not a bad hack, delmoi, but it's broken against comments that are greater than one page -- you'd have to tab and then scroll up, right?
posted by cortex at 3:07 PM on March 28, 2006


tab also has meaning in a lot of browsers: moving to the next hyperlink.
posted by boo_radley at 3:18 PM on March 28, 2006


and to address Matt's question, I think it'd be easier to have an <a name> tag preceding each comment and triggering jumps to each throught js than dinking with divs.
posted by boo_radley at 3:22 PM on March 28, 2006


Good point, boo_radley. Would altering the divs have possible negative ramifications for other existing Mefi-related scripts? It seems like adding an anchor tag would be less likely to cause problems.
posted by cortex at 3:31 PM on March 28, 2006


or, guh, there's an existing <a name> for each comment on the timestamp. Why make a new div at all?
posted by boo_radley at 3:38 PM on March 28, 2006


Not a bad hack, delmoi, but it's broken against comments that are greater than one page -- you'd have to tab and then scroll up, right?

Hmm, in firefox it scrolls the page to put the selected link on the screen.

You can hit shift+tab to go backwards.
posted by delmoi at 3:40 PM on March 28, 2006


tab also has meaning in a lot of browsers: moving to the next hyperlink.

That's why delmoi says 'hit tab three times' I think - I navigate comments here by tabbing through the username/timestamp/flag links, though comments with links in them or very long comments stop that method working.

There was a debate somewhere either here in the grey or in the green about the hotkey issue before, and there were some valid points about it and some sort of conflict.

Yeah, I think the redesign briefly included incredibly handy access keys to jump around between the different sections of the site, but in some browsers the access key combinations buggered up browser-specific command keys. Shame really - access keys are super.
posted by jack_mo at 3:47 PM on March 28, 2006


Not the same thing, but spacebar pages down. That saves me scrolling.
posted by yerfatma at 3:47 PM on March 28, 2006


Man I would LOVE j/k to work like this. It's awesome in Bloglines and gmail and works just fine and I find myself hitting j on mefi constantly.

I don't have find as you type enabled, ever since I found out that / is an alternate to ctrl/cmd-F I find it easier and less annoying and works with my vi muscle memory.

This would be well worth figuring out - when they added it to bloglines I feel like it basically tripled how fast I could go through my crapmountain? THINK OF THE CHILDREN, and thanks in advance.

P.S. If someone makes a greasemonkey script to do this I'd much appreciate a version that does ONLY this.
posted by 31d1 at 4:44 PM on March 28, 2006


yerfatma: "Not the same thing, but spacebar pages down. That saves me scrolling."

The thing that really ends up great about j/k navigation is that your eye stays in the same place as you scroll through. Somehow it really speeds up your mental process.
posted by 31d1 at 4:46 PM on March 28, 2006


Matt:
I haven't looked at the Reblog code (I went to reblog.org but didn't really know where to look), but what Bloglines does is pretty clever.

Basically, you need to work out the position on the page of each comment's anchor tag (the y-coordinate in pixels), and store this in an array. Then, when the user presses j, you work out where their browser is scrolled to on the page (in pixels), and look through your array of comment positions to find the next furthest down comment. Then, scroll to it.

This seems complicated, but it's necessary because: imagine if you scroll halfway down the page (just normally, with scroll-wheel or whatever), and then press j. You don't want to end up back at the second comment (which is somewhere at the top of the page); rather, you want to end up at the next comment relative to where you're currently looking. If I'm not making any sense here, which is quite probable, take a look at bloglines.com (go to 'my feeds'), and try scrolling up and down and pressing j and k.

Looking at the bloglines.com source, the clever part of the script is taken from Matt Kruse (the script is here). Therefore, if we use this script, most of the hard work is done already.
posted by matthewr at 4:55 PM on March 28, 2006


Oh hell yeah, matthewr!
posted by 31d1 at 5:00 PM on March 28, 2006


>Programs like Winamp use a lot of single-stroke hotkeys

>>Yeah, but are they system-wide? In other words, you're using firefox, hit N to go to the next comment, and suddenly the music changes?


Aside: Winamp's global hot keys default to CTL+ALT+key, and are turned off by default, I believe. You can configure 'em how you like, of course. I use them all the time on Friday nights during my beer+RocketArena3+RAWK sessions. If another app has focus and there's overlap in hotkey assignment, the currently focussed app takes precedence for keystrokes, of course. Thus the relatively uncommon CTRL+ALT+ scheme, which pretty much always works regardless of what has focus.
posted by stavrosthewonderchicken at 5:12 PM on March 28, 2006


Shift+space scrolls up in firefox.

I still don't understand why you can you space/shift+space or tab/shift+tab...
posted by delmoi at 5:32 PM on March 28, 2006


The thing that really ends up great about j/k navigation is that your eye stays in the same place as you scroll through.

Gotcha. I never started using the j/k, so I didn't get the difference. I'll have to give it a shot.
posted by yerfatma at 5:35 PM on March 28, 2006


Here you go, jk. It was trivial to add to my comment script. This version has the comment script stuff commented out. I seem to be having some strange interaction.
posted by MonkeySaltedNuts at 5:39 PM on March 28, 2006


MoSaNu: Doesn't work for me, I'm afraid.
posted by matthewr at 5:43 PM on March 28, 2006


Shift+space scrolls up in firefox.

Wha!? Buh!! Kick ass!

*ponders if delmoi even owns a mouse*
posted by loquacious at 5:45 PM on March 28, 2006


#matthewr: Doesn't work for me, I'm afraid.

How doesn't it work? Do you get any error messages in the JavaScript Console? Do pressing "j" and "k" do nothing?

I still need to fix it to take account of the current scroll position.
posted by MonkeySaltedNuts at 5:50 PM on March 28, 2006


MonkeySaltedNuts: "Here you go, jk. It was trivial to add to my comment script. This version has the comment script stuff commented out. I seem to be having some strange interaction."

SWEEEET!!

Two things:
1) bloglines and gmail have j going down, not up, as you have. Could you reverse it?
2) Can you add the same functionality to post pages as well? Or is that a whole other can of worms?
posted by 31d1 at 5:51 PM on March 28, 2006


MoSaNu: Not sure why it's not working. I'm not getting anything in the console, it's just not doing anything when I press j or k. I've turned other scripts off, but that didn't have any effect.
posted by matthewr at 5:52 PM on March 28, 2006


On post-view - yeah knowing the scroll position is key, but it seems like you're not worried about making that happen. You rock, man!
posted by 31d1 at 5:53 PM on March 28, 2006


A-ha! I've worked out what's wrong. I've got the "Begin finding when you begin typing" option switched on in Firefox. Your script needs to cancel the event before the browser gets to it. You need something like this:

if (event.preventDefault) {
event.preventDefault();
event.stopPropagation();
} else {
event.returnValue = false;
}

posted by matthewr at 5:55 PM on March 28, 2006


<a name> is a good way of doing this and obviously it can work without javascript...

<a name="comment1" href="#comment2">#</a> comment 1

<a name="comment2" href="#comment3">#</a>comment 2

Hit enter to move from link to link down the page. Start the chain by hitting tab to the first link in the page then enter to move to the first comment/story (doing one of those "skip menu" links early in the page is good practice anyway).
posted by holloway at 5:59 PM on March 28, 2006


ever since I found out that / is an alternate to ctrl/cmd-F

holy fucking shit
i love you 31d1
posted by cortex at 6:10 PM on March 28, 2006


The "hot key" problems were to do with accesskeys, not these. Access keys were about pressing ALT+KEY and giving focus to part of the page. The problem was that (for example) using ALT-F in a page overrides the browser 'File' menu, and mefi was overriding inbuilt-browser keys. It's a well known issue (see NZ Egovt Web Guidelines) and people recommend that sites only use keys not typically used in software, which are ALT + [0-9 - + = / ].

It'd be fine for Mefi to use ALT-1 for metafilter.com, ALT-2 for Ask, etc.

The event.keyCode Javascript is well-supported in almost every browser but it's similarly affected in that it could conflict with some in-browser features (like search-as-you-type). So then it's about whether the key you choose conflicts with anything and if that thing is used by many people. I don't know -- maybe you could try it and see if there are many complaints.
posted by holloway at 6:12 PM on March 28, 2006


(oh natch Firefox uses ALT-1 ALT-2 ALT-n for switching between tabs... but it changes tabs and runs the access key. That's gotta be a bug)
posted by holloway at 6:22 PM on March 28, 2006


Since you ask, matthewr, I've been kind of jonesing to have a script that automatically links to a user's previous comment when their name is mentioned, and it seems like that would be trivial in your existing navigator, though I haven't cracked open the script to see.

I just want it so when someone responds to someone's comment like I've done here, I don't have to scroll up looking for what they're talking about. I could click the name, and then use your arrows to keep jumping upward if that wasn't the comment in question. Does that make sense? I know people don't always use the full name, so it wouldn't be reliable, but people do often copy or type the name rather than actually quote or link to the comment. Would it be too expensive as you're scanning through the page to check if a word matches a username you've already added to you array?
posted by team lowkey at 6:28 PM on March 28, 2006


AND ANOTHER THING

The main problem is getting an event available. The chain of hyperlinks thing could have an onclick handler that checked the scroll position like these other scripts do.
posted by holloway at 6:31 PM on March 28, 2006


team lowkey: Yeah, that would be cool. I thought about that, but never really got around to implementing it because on threads with 300+ comments, running a regex for, say, 50 to 100 usernames on each comment is probably going to kill your computer for a few minutes. It might be do-able for people with fast computers though. I'll have a think about it.
posted by matthewr at 6:40 PM on March 28, 2006


#31d1: bloglines and gmail have j going down, not up, as you have. Could you reverse it?

A new version of jk reverses my take on j & k.

Also it uses the current window scroll position to decide what comment to scroll to. Let me know if I've made some fencepost or other error with this.
posted by MonkeySaltedNuts at 7:07 PM on March 28, 2006


Very nice, and thanks!

I've found a bit of a bug I think - it's dependant on the size of the browser window so I hope you can duplicate it. When i have hit as many j's as possible, and when my browser window is tall as possible (on a 12" mac) it gets stuck and k won't won't work to scroll back up. Manually moving the scrollbar up a line or two and k works again. It seems like if the previous comment is scrolled up out of the screen it doesn't catch it.

I hope that makes sense :)
posted by 31d1 at 7:31 PM on March 28, 2006


or to make a long story short - it can get stuck at the bottom of the screen.
posted by 31d1 at 7:34 PM on March 28, 2006


This thread is chock full of knowledge nuggets. Of course, my favorite scrolling method is click and hold middle button and move the mouse up or down. It's like a game to see if you can stop on an interesting comment. And easy to scroll past extremely long, extremely insane screeds.
posted by Roger Dodger at 8:11 PM on March 28, 2006


My attempt

Just click the first link on the page then hit enter to move from comment to comment. It'll do some mediocre scrolling between comments. It could be improved to find the Y position of the next comment based on scroll position (the code to make these decisions is there) but it's not currently made that way.
posted by holloway at 9:41 PM on March 28, 2006


My attempt

Hey, wait a minute! People made fun of me for suggesting something like that way back here. Hmmph.

Also: cool.
posted by stavrosthewonderchicken at 9:44 PM on March 28, 2006


By the way, I tried capturing ctrl/shift/alt+enter but it was already used for opening a link in a new window, a new tab, and so on. I haven't tried all combinations of those modifiers though... guess i should check out that modifier bitmask property.
posted by holloway at 9:48 PM on March 28, 2006

Hey, wait a minute! People made fun of me for suggesting something like that way back here. Hmmph.
And here's me with these Internal Hyperlink patent applications already half-filled...

Now I'll have to carefully insert the word "WiFi" before every mention of internal hyperlink. Thanks a lot you jerk!
posted by holloway at 9:59 PM on March 28, 2006


Thank you MonkeySaltedNuts. jk is great. Still, getting it built right into the site would be great for non Firefox/GM users, but for me, I'm satiated.
posted by pithy comment at 10:03 PM on March 28, 2006


Just updated my attempt with silky smooth scrolling like that other guys.
posted by holloway at 10:44 PM on March 28, 2006


Please don't add any name attributes, use id.

or, guh, there's an existing <a name> for each comment on the timestamp. Why make a new div at all?
posted by boo_radley at 6:38 PM EST on March 28 [!]


Because you want to jump to the start of the comment, not the timestamp, and because it'd make it easier to add future thingies for both Matt and third party devs (greasemonkey hackers, etc.)
posted by Firas at 5:18 AM on March 29, 2006


Great stuff - I owe you a nut, holloway. Will test later and report back.
posted by blag at 5:42 AM on March 29, 2006


Hmmm secret plot by Vim religious nuts? j, k, /, what's next : ?
posted by melt away at 5:11 PM on March 29, 2006


secret plot by Vim religious nuts

You're right, what's wrong with M-x metafilter-forward-next-comment?
posted by whir at 10:51 PM on March 29, 2006


Hmm. I can't get jk to work, monkeysaltednuts - I get a Greasemonkey error whenever I try to install the script:



Any ideas?
posted by blag at 1:38 PM on March 30, 2006


Follow up... the jk greasemonkey script seems to skip "best answers" in Ask MetaFilter. There is no email in Monkey Salted Nuts' profile.
posted by pithy comment at 1:05 PM on April 18, 2006


« Older Phoenix Meetup   |   Jeopardy Online Meetup Newer »

You are not logged in, either login or create an account to post comments