Next Previous Image Key Navigation

Quick scroll to next/previous image on a page with f/r buttons

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name Next Previous Image Key Navigation
// @author waka <[email protected]>
// @namespace http://waka.name/
// @version 1.0.1
// @description  Quick scroll to next/previous image on a page with f/r buttons
// @include *
// ==/UserScript==

(function(){
  var sizeLimit = 200;
  var rButton = 114;
  var fButton = 102;
  var positions = [];
  var offsetshift = 0;
  //shift pixels down to avoid floating bars - format: domain,pixels,domain,pixels,...
  //example: http://foo.example.com/ -> domain=example - assume 25 pixels shift -> ,"example","25"
  var shift=["facebook","40","sankakucomplex","25","soup","34","reddit","50"];
  
  document.addEventListener('keypress', keypressHandler, false);
  
  function keypressHandler(event){
    if (event.ctrlKey || event.shiftKey || event.altKey) return;
    if (event.target.tagName && event.target.tagName.match(/input|select|textarea/i)) return;

    var code = event.keyCode || event.which;
    if (code != rButton && code != fButton) return;

    if (positions.length < document.images.length) {
      positions = [];
      for (var index = 0; index < document.images.length; index++) {
        var image = document.images[index];
        if (Math.min(image.width, image.height) < sizeLimit) continue;
        positions.push(getYOffset(image));
      }
    }

    var scroll = Math.max(document.documentElement.scrollTop, document.body.scrollTop);

    positions = positions.sort(sort);
    var next = true;

    if (code == rButton) {
      positions = positions.reverse();
      next = false;
    }
    
    var domain = window.location.host.split('.')[1];
    var length = shift.length,
    element = null;
    for (var i = 0; i < length; i++) {
        element = shift[i];
        // Do something with element i.
        if (domain == element) {
            p = i + 1;
            offsetshift = shift[p];
        }
        i++;
    }

    for (index = 0; index < positions.length; index++) {
      var offset = positions[index] - offsetshift;
      if ((next && offset <= scroll) || (!next && offset >= scroll)) continue;
      scrollTo(offset, scroll);
      return;
    }
  }
  
  function scrollTo(offset, currentScroll) {
    if (currentScroll == document.documentElement.scrollTop) {
      document.documentElement.scrollTop = offset;
    } else {
      document.body.scrollTop = offset;
    }
  }
  
  function getYOffset(node) {
    for (var offset = 0; node; offset += node.offsetTop, node = node.offsetParent);
    return offset;
  }
  
  function sort(a, b) { return a < b ? -1 : 1; }
})()