Link & Form Field Navigation Shortcuts

Adds keyboard shortcuts for focusing: previous form field (ALT+1), next form field (ALT+2), previous link (ALT+3), and next link (ALT+4).

28.02.2018 itibariyledir. En son verisyonu görün.

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         Link & Form Field Navigation Shortcuts
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @license      AGPL v3
// @description  Adds keyboard shortcuts for focusing: previous form field (ALT+1), next form field (ALT+2), previous link (ALT+3), and next link (ALT+4).
// @author       jcunews
// @match        *://*/*
// @grant        none
// ==/UserScript==

function isElementFocusable(ele, css) {
  while (ele && (ele !== document)) {
    if (!ele.offsetWidth || !ele.offsetHeight || ((css = getComputedStyle(ele)) && (css.display === "none"))) return false;
    ele = ele.parentNode;
  }
  return true;
}

addEventListener("keypress", function(ev, eles, i) {
  if ((["1", "2"].indexOf(ev.key) >= 0) && !ev.location && ev.altKey && !ev.ctrlKey) {
    eles = Array.prototype.slice.call(document.querySelectorAll("input, select, textarea"));
    if (document.activeElement && (["INPUT", "SELECT", "TEXTAREA"].indexOf(document.activeElement.tagName) >= 0)) {
      eles.some(function(ele, i) {
        if (ele === document.activeElement) {
          ele = ev.key === "1" ? eles[i - 1] || eles[eles.length - 1] : eles[i + 1] || eles[0];
          while (ele) {
            if (isElementFocusable(ele)) {
              ele.focus();
              ele.scrollIntoView(false);
              return true;
            }
            i += ev.key === "1" ? -1 : 1;
            ele = eles[i];
          }
        }
      });
    } else if (ele = eles[ev.key === "1" ? eles.length - 1 : 0]) {
      ele.scrollIntoView();
      ele.focus();
    }
  } else if ((["3", "4"].indexOf(ev.key) >= 0) && !ev.location && ev.altKey && !ev.ctrlKey) {
    eles = Array.prototype.slice.call(document.querySelectorAll("a"));
    if (document.activeElement && (document.activeElement.tagName === "A")) {
      eles.some(function(ele, i) {
        if (ele === document.activeElement) {
          ele = ev.key === "3" ? eles[i - 1] || eles[eles.length - 1] : eles[i + 1] || eles[0];
          while (ele) {
            if (ele.href && isElementFocusable(ele)) {
              ele.focus();
              ele.scrollIntoView(false);
              return true;
            }
            i += ev.key === "1" ? -1 : 1;
            ele = eles[i];
          }
        }
      });
    } else if (ele = eles[ev.key === "3" ? eles.length - 1 : 0]) {
      ele.scrollIntoView();
      ele.focus();
    }
  }
});