Half page (up/down) scroll

scrolls half a page when pressing page up / down

当前为 2023-06-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Half page (up/down) scroll
  3. // @namespace https://github.com/Alistair1231/my-userscripts/
  4. // @version 0.2.0
  5. // @description scrolls half a page when pressing page up / down
  6. // @author Alistair1231
  7. // @match *://*/*
  8. // @license MIT
  9. // ==/UserScript==
  10. // https://greasyfork.org/en/scripts/444151-half-page-up-down-scroll/
  11. // https://openuserjs.org/scripts/Alistair1231/Half_page_(updown)_scroll
  12. (function () {
  13. 'use strict';
  14.  
  15. document.addEventListener('keydown', function (e) {
  16. // page down
  17. if (e.key === "PageDown") {
  18. e.preventDefault();
  19. window.scrollBy(0, window.innerHeight*.45);
  20. console.log("page down");
  21. }
  22. // page up
  23. else if (e.key === "PageUp") {
  24. e.preventDefault();
  25. window.scrollBy(0, -window.innerHeight*.45);
  26. console.log("page up");
  27. }
  28. });
  29.  
  30. })();