Implemented Jump to posts shortcut.

Discussion in 'Feedback & Assistance' started by Jiηx, Aug 20, 2012.

  1. Jiηx You're such a loser.

    Joined:
    Sep 27, 2006
    Gender:
    Lord
    Location:
    Twisting like a flame in a slow dance, baby.
    1,426
    I'm sure you've all at least used one of the sites that have this feature, I know 9gag, Tumblr and Memebase all use it, but it's basically where you hit the "J" key usually and it jumps to the next post on the page, well I thought, why doesn't KHV try that? So I acquired this script and it's been tested on Chrome and works perfectly:

    $(document).keydown(function(e){
    var locaPrev = $('nav:contains("< Prev"):first a:contains("< Prev")').attr("href");
    var locaNext = $('nav:contains("Next >"):first a:contains("Next >")').attr("href");
    if (e.keyCode == 74 && e.altKey) {
    window.location.href = locaPrev;
    };
    if (e.keyCode == 75 && e.altKey) {
    window.location.href = locaNext;
    };
    });

    Due to the quick reply function, simply having J and K being the keys used to jump between posts would make it so it's impossible to use J and K in quick reply posts, so the script has been modified to solve that, for this you type in Alt+J to go to the next post and Alt+K to go the previous post.

    ^ there's a slight error, this code jumps between pages, if you'll give me a moment I'll get one that jumps between posts.

    I just figured this'd make lives easier for lazy members like myself, opinions?
     
  2. jafar custom title

    Joined:
    Dec 28, 2007
    1,652
    I think this feature would be groovy. There's tons of posts that appear on a page now and it would make it seem significantly less overwhelming.
     
  3. Misty gimme kiss

    Joined:
    Sep 25, 2006
    Gender:
    Cisgender Female
    Location:
    alderaan
    6,590
    ... couldn't you basically do the same thing by hitting the Page Up/Down keys?
     
  4. jafar custom title

    Joined:
    Dec 28, 2007
    1,652
    Because Vivi is a loser and went to bed, I'm posting this on his behalf.

    This is the new code for post jumping.

    The one in the OP is for page jumping.

    EDIT: I placed in a new code, which is faster and smoother.

    Code:
    $(document).keydown(function(e){
     
    if (e.keyCode == 74 && e.altKey) {
     
    var i = $("ol.messageList li.message").length;
     
    var Posi = $('html').offset();
    var Posit = String(Posi.top).replace(/-/g, "");
    curPos = parseInt(Posit);
     
    while ($("ol.messageList li.message:nth-child("+i+")").offset().top >= curPos) {
    i--
    }
     
    var nextMessage = $("ol.messageList li.message:nth-child("+i+")").offset();
     
    if (curPos >= nextMessage.top) {
    $('body').animate({ scrollTop: nextMessage.top }, { duration: 'fast', easing: 'swing'});
    // $(document).scrollTop(nextMessage.top);
    }
     
    if (i < 1) {
    var i = $("ol.messageList li.message").length;
    }
     
    };
     
    if (e.keyCode == 75 && e.altKey) {
     
    var i = 1;
     
    var Posi = $('html').offset();
    var Posit = String(Posi.top).replace(/-/g, "");
    curPos = parseInt(Posit);
     
    while ($("ol.messageList li.message:nth-child("+i+")").offset().top <= curPos) {
    i++
    }
     
    var nextMessage = $("ol.messageList li.message:nth-child("+i+")").offset();
     
    if (curPos <= nextMessage.top) {
    $('body').animate({ scrollTop: nextMessage.top }, { duration: 'fast', easing: 'swing'});
    // $(document).scrollTop(nextMessage.top);
    }
     
    if (i > $("ol.messageList li.message").length) {
    var i = 1;
    }
     
    };
    });
     
  5. Boy Wonder Dark Phoenix in Training

    Joined:
    Aug 31, 2008
    Gender:
    Male
    Location:
    Genosha
    2,239
    ...So this is the equivalent of scrolling down?
     
  6. DigitalAtlas Don't wake me from the dream.

    Joined:
    Oct 1, 2006
    Location:
    Blossom City
    2,335
    Just tested this and LOVE IT. It'll help so much when there's a long post I'm trying to skip over or quickly skim through the forum without wanting to go to my mouse!

    WIN!
    WIN!
    WIN!

    EDIT: For those who want to test it:

    HOW TO TEST IN GOOGLE CHROME
    Step 1. Be in this thread and stay here. Awesome.
    Step 2. Right-Click on Rainshine's post
    Step 3. Click on "inspect element" from the right click menu.
    Step 4. Click on console
    Step 5. Paste Rainshine's code into there and press enter.
    Step 6. Click on thread.
    Step 7. Press Alt+K or Alt+J to test out the function. One will move up posts, the other down.
    (OPTIONAL) Step 8. Like Rainshine's post.

    To test in FireFox, you must use FireBug
     
  7. Inasuma "pumpkin"

    Joined:
    Sep 25, 2006
    Location:
    Indigo Plateau
    277
    this is actually a pretty good idea. as long as things stay clean i don't see the harm.

    also, 1-up for my homie craig.
     
  8. Peace and War Bianca, you minx!

    Joined:
    May 25, 2007
    Gender:
    Cisgender Male
    1,282
    Effectively, but I guess there are several ways to be lazy. Scrolling down is just my own vice of laziness and I doubt that'll change through choice.

    Not really much of an opinion on the topic as a whole. Neutral.
     
  9. Jiηx You're such a loser.

    Joined:
    Sep 27, 2006
    Gender:
    Lord
    Location:
    Twisting like a flame in a slow dance, baby.
    1,426
    Not really no, those just jump to set points on the page, this actually takes the next post on the page and sets it to that, if someone posted a 3 month long post, page up page down would just be jumping to different points on that, this actually just takes you directly to the next post on the thread.
     
  10. jafar custom title

    Joined:
    Dec 28, 2007
    1,652
    New and improved code:

    This one now works at different zooms.

    EDIT: Now uses CTRL instead of ALT, so no more dinging sounds!

    Code:
    $(document).keydown(function(e){
     
    if (e.keyCode == 74 && e.ctrlKey) {
     
    if ($("ol.messageList li.message").length > 0) {
    e.preventDefault();
    };
     
    var i = $("ol.messageList li.message").length;
     
    var Posi = $('html').offset();
    var Posit = String(Posi.top).replace(/-/g, "");
    curPos = parseInt(Posit);
     
    while ($("ol.messageList li.message:nth-child("+i+")").offset().top >= curPos) {
    i--
    }
     
    var nextMessage = $("ol.messageList li.message:nth-child("+i+")").offset();
     
    if (curPos >= nextMessage.top) {
    $('body').animate({ scrollTop: nextMessage.top }, { duration: 'fast', easing: 'swing'});
    // $(document).scrollTop(nextMessage.top);
    }
     
    if (i < 1) {
    var i = $("ol.messageList li.message").length;
    }
     
    return false;
    };
     
    if (e.keyCode == 75 && e.ctrlKey) {
     
    if ($("ol.messageList li.message").length > 0) {
    e.preventDefault();
    };
     
    var i = 1;
     
    var Posi = $('html').offset();
    var Posit = String(Posi.top).replace(/-/g, "");
    curPos = parseInt(Posit);
     
    while ($("ol.messageList li.message:nth-child("+i+")").offset().top <= curPos + 2) {
    i++
    };
     
    var nextMessage = $("ol.messageList li.message:nth-child("+i+")").offset();
     
    if (curPos <= nextMessage.top) {
    $('body').animate({ scrollTop: nextMessage.top }, { duration: 'fast', easing: 'swing'});
    // $(document).scrollTop(nextMessage.top);
    };
     
    if (i > $("ol.messageList li.message").length) {
    var i = 1;
    };
     
    return false;
    };
    });