Lessons touchpad swipe navigation

Navigate your lessons with swipe gesture ("wheel" event)

  1. // ==UserScript==
  2. // @name Lessons touchpad swipe navigation
  3. // @namespace wanikani
  4. // @version 0.1
  5. // @description Navigate your lessons with swipe gesture ("wheel" event)
  6. // @author mrowqa
  7. // @match https://www.wanikani.com/lesson/session
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. $(document).ready(function() {
  12. 'use strict';
  13.  
  14. function touchpadScrollHandler(event) {
  15. //console.log("X: " + event.deltaX + ", " + event.deltaY + ", " + event.deltaZ);
  16. if (touchpadScrollHandler.locked === true) {
  17. return;
  18. }
  19. //console.log("next");
  20.  
  21. var threshold = 3; // for mouse event deltaX value, 10-20 slow swipe, >100 fast swipes
  22. var cooldown = 2000; // in miliseconds
  23. var leftKeyCode = 37;
  24. var rightKeyCode = 39;
  25.  
  26. var scroll = function (keyCode) {
  27. $("body").trigger(
  28. $.Event("keyup", {keyCode: keyCode, which: keyCode})
  29. );
  30. touchpadScrollHandler.locked = true;
  31. setTimeout(function() {
  32. touchpadScrollHandler.locked = false;
  33. }, cooldown);
  34. };
  35.  
  36. if (event.deltaX < -threshold) {
  37. scroll(leftKeyCode);
  38. }
  39. if (event.deltaX > threshold) {
  40. scroll(rightKeyCode);
  41. }
  42. }
  43.  
  44. touchpadScrollHandler.locked = false;
  45. document.addEventListener("wheel", touchpadScrollHandler, {passive: true});
  46. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址