APUG.org show image keyboard control

Keyboard navigation for APUG user gallery images.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        APUG.org show image keyboard control
// @namespace   http://oscar.carlsson.photography/
// @description Keyboard navigation for APUG user gallery images.
// @include     http://www.apug.org/gallery1/showimage.php?i=*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @version     1
// @grant       none
// ==/UserScript==
function find_links() {
  links = {};
  
  $('div.smallfont a').each(function (e) {
    if ($(this) [0].textContent === 'Previous Image')
      links.prev = $(this) [0];

    if ($(this) [0].textContent === 'Next Image')
      links.next = $(this) [0];
  });
  return links;
}

function upwards() {
  var breadcrumbs = $('div#breadcrumb li.navbit'),
      previous = null;
  for (var index = 0; index < breadcrumbs.length; index++) {
    var breadcrumb = breadcrumbs[index],
        classes = breadcrumb.className.split(/\s+/);
    
    if ($.inArray('lastnavbit', classes) === - 1) {
      previous = breadcrumb;
      continue;
    } else {
      // fetch link from the previous element
      var children = $(previous).children();
      for (var idx = 0; idx < children.length; idx++) {
        var child = children[idx],
        url = child.href;
        if (url) window.location.assign(url);
      }
    }
  }
}

$(window).keyup(function (e) {
  var key = e.keyCode;

  if (key == 39 || key == 37)
    var links = find_links();

  if (key == 37) {
    window.location.assign(links.prev.href);
    return;
  }
  if (key == 39) {
    window.location.assign(links.next.href);
    return;
  }
  if (key == 85) { // u
    upwards();
    return;
  }
});