Fix Editor scroll zoom sensitivity - Bonk.io

Fixes scrolling in the editor causing zoom to go ZOOOM (ie when using a trackpad)

  1. // ==UserScript==
  2. // @name Fix Editor scroll zoom sensitivity - Bonk.io
  3. // @description Fixes scrolling in the editor causing zoom to go ZOOOM (ie when using a trackpad)
  4. // @author Excigma
  5. // @namespace https://github.com/Excigma
  6. // @license GPL-3.0
  7. // @version 0.0.2
  8. // @match https://bonk.io/gameframe-release.html
  9. // @grant none
  10. // @run-at document-idle
  11. // ==/UserScript==
  12.  
  13. (() => {
  14. const REVERSE_SCROLL = false;
  15. const SENSITIVITY = 0.02;
  16.  
  17. const mapeditor_midbox_previewcontainer = document.querySelector("#mapeditor_midbox_previewcontainer");
  18. const classic_mid_customgame = document.getElementById("classic_mid_customgame");
  19.  
  20. // This requires the newest version of kklee
  21. classic_mid_customgame.addEventListener("click", () => {
  22. if (!window.kklee) {
  23. alert("Editor scroll zoom tweaks requires kklee to be installed.\nMake sure you have kklee installed.\nIf you have it installed:\n- either kklee failed to load\n- or kklee changed its code and is no longer compatible");
  24. } else {
  25. let scroll_amount = 0;
  26. mapeditor_midbox_previewcontainer.addEventListener("wheel", evt => {
  27. scroll_amount += evt.deltaY * SENSITIVITY * (REVERSE_SCROLL ? 1 : -1);
  28.  
  29. // Once a threshold is reached...
  30. if (scroll_amount > 1) {
  31. // Zoom in
  32. window.kklee.stageRenderer.scaleStage(1.25);
  33. window.kklee.updateRenderer();
  34. scroll_amount = 0;
  35. } else if (scroll_amount < -1) {
  36. // Zoom out
  37. window.kklee.stageRenderer.scaleStage(0.8);
  38. window.kklee.updateRenderer();
  39. scroll_amount = 0;
  40. }
  41. // Don't let bonk.io handle the scroll event
  42. evt.stopImmediatePropagation();
  43. evt.preventDefault();
  44. });
  45. }
  46. });
  47. })();