Movement particles

Adds particles when walking

  1. // ==UserScript==
  2. // @name Movement particles
  3. // @namespace -
  4. // @version 0.1.2
  5. // @description Adds particles when walking
  6. // @author Devil D. Nudo#7346
  7. // @match *://*.moomoo.io/*
  8. // @match *://moomoo.io/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=moomoo.io
  10. // @run-at document-start
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. function particles() {
  16. function getRandom(min, max) {
  17. return Math.floor(Math.random() * (max - min)) + min
  18. }
  19.  
  20. function getRandomRGBA(alpha) {
  21. const r = Math.round(255 * Math.random())
  22. const g = Math.round(255 * Math.random())
  23. const b = Math.round(255 * Math.random())
  24. const a = alpha ?? 1
  25.  
  26. return `rgba(${r}, ${g}, ${b}, ${a})`
  27. }
  28.  
  29. let lastX = 0
  30. let lastY = 0
  31.  
  32. class Vector {
  33. constructor(x = 0, y = 0) {
  34. this.x = x
  35. this.y = y
  36. }
  37.  
  38. static random2D(angle, length = 1) {
  39. return new Vector(length * Math.cos(angle), length * Math.sin(angle))
  40. }
  41.  
  42. get magnitude() {
  43. return Math.sqrt(this.x ** 2 + this.y ** 2)
  44. }
  45.  
  46. setMag(length) {
  47. return this.normalize().mult(length)
  48. }
  49.  
  50. add(x, y) {
  51. const vector = new Vector(x, y)
  52.  
  53. this.x += vector.x
  54. this.y += vector.y
  55.  
  56. return this
  57. }
  58.  
  59. sub(vector) {
  60. this.x -= vector.x
  61. this.y -= vector.y
  62.  
  63. return this
  64. }
  65.  
  66. mult(scalar) {
  67. this.x *= scalar
  68. this.y *= scalar
  69.  
  70. return this
  71. }
  72.  
  73. div(divisor) {
  74. this.x /= divisor
  75. this.y /= divisor
  76.  
  77. return this
  78. }
  79.  
  80. normalize() {
  81. const mag = this.magnitude
  82.  
  83. if (mag > 0) {
  84. this.div(mag)
  85. }
  86.  
  87. return this
  88. }
  89. }
  90.  
  91. class Physics {
  92. constructor(x, y, mass = 5, time = 0.9) {
  93. this.mass = mass
  94. this.time = time
  95.  
  96. this.position = new Vector(x, y)
  97. this.velocity = new Vector()
  98. this.acceleration = new Vector()
  99. this.force = new Vector()
  100. }
  101.  
  102. updatePhysics() {
  103. this.force.div(this.mass)
  104.  
  105. this.acceleration.add(this.force.x, this.force.y)
  106. this.acceleration.mult(this.time)
  107.  
  108. this.velocity.add(this.acceleration.x, this.acceleration.y)
  109. this.velocity.mult(this.time)
  110.  
  111. this.position.add(this.velocity.x, this.velocity.y)
  112. }
  113. }
  114.  
  115. class Particle extends Physics {
  116. constructor({ id, scale, color }, context, xOffset, yOffset, myPlayer) {
  117. super(myPlayer.x, myPlayer.y)
  118.  
  119. this.id = id
  120. this.maxScale = scale
  121. this.color = color
  122. this.context = context
  123. this.xOffset = xOffset
  124. this.yOffset = yOffset
  125.  
  126. this.scale = 0
  127.  
  128. this.alpha = 0
  129. this.maxAlpha = 1
  130.  
  131. this.liveTime = getRandom(350, 600)
  132. this.liveDate = Date.now()
  133.  
  134. let mag = getRandom(1, 10)
  135.  
  136. const speed = Math.hypot(lastY - myPlayer.y, lastX - myPlayer.x)
  137. const direction = Math.atan2(lastY - myPlayer.y, lastX - myPlayer.x)
  138. const point = new Physics(myPlayer.x, myPlayer.y)
  139.  
  140. point.velocity.add(speed * Math.cos(direction), speed * Math.sin(direction))
  141.  
  142. point.updatePhysics()
  143.  
  144. this.moveDir = Math.atan2(point.position.y - myPlayer.y, point.position.x - myPlayer.x)
  145.  
  146. if (speed <= 0.15) {
  147. mag = 0
  148.  
  149. this.moveDir = 0
  150. }
  151.  
  152. this.velocity = Vector.random2D((this.moveDir - Math.PI / 6) + Math.random() * Math.PI * .35).setMag(mag)
  153.  
  154. lastX = myPlayer.x
  155. lastY = myPlayer.y
  156. }
  157.  
  158. get liveTimer() {
  159. return Date.now() - this.liveDate
  160. }
  161.  
  162. render() {
  163. this.context.save()
  164. this.context.fillStyle = this.color
  165. this.context.globalAlpha = this.alpha
  166. this.context.beginPath()
  167. this.context.arc(this.position.x - this.xOffset, this.position.y - this.yOffset, this.scale, 0, 2 * Math.PI)
  168. this.context.fill()
  169. this.context.restore()
  170. }
  171.  
  172. update() {
  173. this.updatePhysics()
  174.  
  175. this.scale = (this.liveTimer / this.liveTime) * this.maxScale
  176. this.alpha = (this.liveTimer / this.liveTime) * this.maxAlpha
  177.  
  178. this.render()
  179.  
  180. if (this.liveTimer >= this.liveTime) {
  181. _particles.remove(this.id)
  182. }
  183. }
  184. }
  185.  
  186. class Particles {
  187. constructor() {
  188. this.particles = {}
  189. }
  190.  
  191. get list() {
  192. return Object.values(this.particles)
  193. }
  194.  
  195. create(be, f, d, R) {
  196. const id = Date.now() / 111
  197.  
  198. this.particles[id] = new Particle({
  199. id: id,
  200. scale: getRandom(5, 12),
  201. color: getRandomRGBA()
  202. }, be, f, d, R)
  203. }
  204.  
  205. remove(id) {
  206. delete this.particles[id]
  207. }
  208.  
  209. update(be, f, d, R) {
  210. this.create(be, f, d, R)
  211.  
  212. let i = this.list.length
  213.  
  214. while (i--) {
  215. this.list[i].update()
  216. }
  217. }
  218. }
  219.  
  220. return new Particles()
  221. }
  222.  
  223. function applyRegex(code) {
  224. code = code.replace(/\,._blank.\)\}/, `,"_blank")};\n${particles.toString()};\n const _particles = particles();\n`)
  225.  
  226. const { index } = code.match(/\.drawImage\(\w+\.skull\,/)
  227. const contextVariable = code.slice(index - 2, index)
  228.  
  229. code = code.replace(/\_\.health\>\d/, `;_particles.update(${contextVariable}, f, d, R);_.health>0`)
  230.  
  231. return code
  232. }
  233.  
  234. async function loadScript(script) {
  235. const response = await fetch(script.src)
  236.  
  237. let code = await response.text()
  238.  
  239. code = applyRegex(code)
  240.  
  241. eval(code)
  242. }
  243.  
  244.  
  245. const observer = new MutationObserver(function(mutations) {
  246. for (const mutation of mutations) {
  247. for (const node of mutation.addedNodes) {
  248. if (node.tagName === "SCRIPT" && /bundle\.js$/.test(node.src)) {
  249. observer.disconnect()
  250.  
  251. loadScript(node)
  252.  
  253. node.remove()
  254. }
  255. }
  256. }
  257. })
  258.  
  259. observer.observe(document, {
  260. childList: true,
  261. subtree: true
  262. })
  263. })()

QingJ © 2025

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