Sploop.io Zoom hack

Allows to change zoom of the game using mouse wheels

Zainstaluj skrypt?
Skrypt zaproponowany przez autora

Może Ci się również spodobać. Dsync Client [Sploop.io]

Zainstaluj skrypt
  1. // ==UserScript==
  2. // @name Sploop.io Zoom hack
  3. // @author Murka
  4. // @description Allows to change zoom of the game using mouse wheels
  5. // @icon https://sploop.io/img/ui/favicon.png
  6. // @version 0.5
  7. // @match *://sploop.io/*
  8. // @run-at document-start
  9. // @grant none
  10. // @license MIT
  11. // @namespace https://greasyfork.org/users/919633
  12. // ==/UserScript==
  13. /* jshint esversion:6 */
  14.  
  15. /*
  16. Author: Murka
  17. Github: https://github.com/Murka007
  18. Discord: https://discord.gg/sG9cyfGPj5
  19. Greasyfork: https://greasyfork.org/en/users/919633
  20. */
  21.  
  22. (function() {
  23. "use strict";
  24.  
  25. const log = console.log;
  26. function createHook(target, prop, callback) {
  27. const symbol = Symbol(prop);
  28. Object.defineProperty(target, prop, {
  29. get() {
  30. return this[symbol];
  31. },
  32. set(value) {
  33. callback(this, symbol, value);
  34. },
  35. configurable: true
  36. })
  37. }
  38.  
  39. function findKey(target, value) {
  40. for (const key in target) {
  41. if (target[key] === value) return key;
  42. }
  43. return null;
  44. }
  45.  
  46. const CONFIG = {
  47. maxWidth: {
  48. key: null,
  49. value: 1824 + 100 * 6
  50. },
  51. maxHeight: {
  52. key: null,
  53. value: 1026 + 100 * 6
  54. }
  55. };
  56.  
  57. // "max_players", is the only way to get access to the max_width and max_height properties
  58. // otherwise I would have to hook setTransform or Math.max
  59. createHook(Object.prototype, "max_players", function(that, symbol, value) {
  60. delete Object.prototype.max_players;
  61. that.max_players = value;
  62.  
  63. const { maxWidth, maxHeight } = CONFIG;
  64. maxWidth.key = findKey(that, 1824);
  65. maxHeight.key = findKey(that, 1026);
  66.  
  67. Object.defineProperty(that, maxWidth.key, { get: () => maxWidth.value })
  68. Object.defineProperty(that, maxHeight.key, { get: () => maxHeight.value })
  69. })
  70.  
  71. let wheels = 0;
  72. const scaleFactor = 150;
  73. window.addEventListener("wheel", function(event) {
  74. const { maxWidth, maxHeight } = CONFIG;
  75. if (event.target.id !== "game-canvas" || maxWidth.key === null || maxHeight.key === null) return;
  76.  
  77. // Used to create a small gap, so users could easily find the default scale
  78. if (maxWidth.value === 1824 && maxHeight.value === 1026) wheels += 1;
  79. if (wheels % 5 !== 0) return;
  80.  
  81. const zoom = event.deltaY > 0 ? -scaleFactor : scaleFactor;
  82. maxWidth.value += zoom;
  83. maxHeight.value += zoom;
  84. window.dispatchEvent(new Event("resize"));
  85. })
  86.  
  87. })();