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).

  1. // ==UserScript==
  2. // @name Extended SPACE Key Page Scroller
  3. // @namespace ExtendedSpaceKeyPageScroller
  4. // @version 1.0.3
  5. // @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).
  6. // @author jcunews
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12.  
  13. // *** Configuration Start ***
  14.  
  15. // QuarterScrollKey: Determine what key combination to use for scrolling page by a quarter height of view.
  16. // 0 = Use both SHIFT keys. i.e. LeftShift+RightShift+Space
  17. // 1/else = Use CAPSLOCK key. i.e. Shift+CapsLock+Space
  18. var QuarterScrollKey = 1;
  19.  
  20. // *** Configuration End ***
  21.  
  22.  
  23. var shiftKeys = 0, capsLock = false;
  24.  
  25. addEventListener("keydown", function(ev) {
  26. switch (ev.which) {
  27. case 16: //SHIFT
  28. shiftKeys |= ev.location;
  29. break;
  30. case 20: //CAPSLOCK
  31. capsLock = true;
  32. }
  33. }, true);
  34.  
  35. addEventListener("keyup", function(ev) {
  36. switch (ev.which) {
  37. case 16: //SHIFT
  38. shiftKeys &= ~ev.location;
  39. break;
  40. case 20: //CAPSLOCK
  41. capsLock = false;
  42. }
  43. }, true);
  44.  
  45. addEventListener("keypress", function(ev, delta) {
  46. if (!ev.shiftKey) {
  47. shiftKeys = 0;
  48. } else if (!shiftKeys) {
  49. shiftKeys = 1;
  50. }
  51. if ((ev.which === 32) && !ev.altKey && (["INPUT", "TEXTAREA"].indexOf(document.activeElement.tagName) < 0)) {
  52. if (((shiftKeys === 3) && !capsLock && !QuarterScrollKey) || //with both SHIFT key
  53. (shiftKeys && (shiftKeys < 3) && capsLock && QuarterScrollKey)) { //with SHIFT+CAPSLOCK key
  54. delta = 4;
  55. } else if (shiftKeys) { //with one SHIFT key
  56. delta = 2;
  57. } else delta = 0;
  58. if (delta) {
  59. scrollBy(0, innerHeight / delta);
  60. ev.preventDefault();
  61. ev.stopPropagation();
  62. ev.stopImmediatePropagation();
  63. }
  64. }
  65. }, true);