Extended SPACE Key Page Scroller

By default the SPACE key scrolls the page down by full height of browser view. With this script, pressing SHIFT+SPACE will scroll half of the view height. Page scroll by a quarter view height can be done using either LEFTSHIFT+RIGHTSHIFT+SPACE or SHIFT+CAPSLOCK+SPACE (configurable via variable).

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Extended SPACE Key Page Scroller
// @namespace    ExtendedSpaceKeyPageScroller
// @version      1.0.3
// @description  By default the SPACE key scrolls the page down by full height of browser view. With this script, pressing SHIFT+SPACE will scroll half of the view height. Page scroll by a quarter view height can be done using either LEFTSHIFT+RIGHTSHIFT+SPACE or SHIFT+CAPSLOCK+SPACE (configurable via variable).
// @author       jcunews
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==


// *** Configuration Start ***

// QuarterScrollKey: Determine what key combination to use for scrolling page by a quarter height of view.
// 0      = Use both SHIFT keys. i.e. LeftShift+RightShift+Space
// 1/else = Use CAPSLOCK key. i.e. Shift+CapsLock+Space
var QuarterScrollKey = 1;

// *** Configuration End ***


var shiftKeys = 0, capsLock = false;

addEventListener("keydown", function(ev) {
  switch (ev.which) {
    case 16: //SHIFT
      shiftKeys |= ev.location;
      break;
    case 20: //CAPSLOCK
      capsLock = true;
  }
}, true);

addEventListener("keyup", function(ev) {
  switch (ev.which) {
    case 16: //SHIFT
      shiftKeys &= ~ev.location;
      break;
    case 20: //CAPSLOCK
      capsLock = false;
  }
}, true);

addEventListener("keypress", function(ev, delta) {
  if (!ev.shiftKey) {
    shiftKeys = 0;
  } else if (!shiftKeys) {
    shiftKeys = 1;
  }
  if ((ev.which === 32) && !ev.altKey && (["INPUT", "TEXTAREA"].indexOf(document.activeElement.tagName) < 0)) {
    if (((shiftKeys === 3) && !capsLock && !QuarterScrollKey) || //with both SHIFT key
        (shiftKeys && (shiftKeys < 3) && capsLock && QuarterScrollKey)) { //with SHIFT+CAPSLOCK key
      delta = 4;
    } else if (shiftKeys) { //with one SHIFT key
      delta = 2;
    } else delta = 0;
    if (delta) {
      scrollBy(0, innerHeight / delta);
      ev.preventDefault();
      ev.stopPropagation();
      ev.stopImmediatePropagation();
    }
  }
}, true);