Greasy Fork 支持简体中文。

Project Random - wowee fun question marks

spinny spin

  1. // ==UserScript==
  2. // @name Project Random - wowee fun question marks
  3. // @namespace https://greasyfork.org/en/users/945115-unmatchedbracket
  4. // @match https://0xbeef.co.uk/random*
  5. // @grant none
  6. // @version 1.0
  7. // @author Unmatched Bracket
  8. // @description spinny spin
  9. // @license The Unlicense
  10. // ==/UserScript==
  11.  
  12. function tickq(e) {
  13. //requestAnimationFrame(() => tickq(e))
  14.  
  15. if (mousepos) {
  16. let rect = e.getBoundingClientRect()
  17. let mouseRelX = (rect.left + rect.right) / 2 - mousepos.x
  18. let mouseRelY = (rect.top + rect.bottom) / 2 - mousepos.y
  19.  
  20. let angleToMouse = Math.atan2(mouseRelY, mouseRelX)*180/Math.PI - 90
  21. let diff = ((e.qdata.angle - angleToMouse) % 360 + 540) % 360 - 180
  22. let dist = Math.hypot(mouseRelX, mouseRelY)
  23. e.qdata.momentum -= diff / Math.pow(Math.max(1, dist/50), 2)
  24. }
  25.  
  26. let now = Date.now()
  27. let delta = now - e.qdata.lasttick
  28. e.qdata.lasttick = now
  29.  
  30. e.qdata.momentum *= 0.95
  31. e.qdata.momentum += Math.pow(Math.random(), 8)*25
  32. e.qdata.angle += e.qdata.momentum*delta/1000
  33. e.style.rotate = e.qdata.angle + "deg"
  34. }
  35.  
  36. let qs = [...document.getElementsByClassName("mark")]
  37.  
  38. let container = qs[0].parentElement.parentElement
  39.  
  40. let mousepos = null
  41.  
  42. container.addEventListener("mousemove", (e) => {
  43. mousepos = {x: e.pageX, y: e.pageY}
  44. })
  45.  
  46. container.addEventListener("mouseenter", (e) => {
  47. mousepos = {x: e.pageX, y: e.pageY}
  48. })
  49.  
  50. container.addEventListener("mouseleave", (e) => {
  51. mousepos = null
  52. })
  53.  
  54. qs.forEach((e) => {
  55. e.style.animation = "none"
  56. //e.style.transition = "rotate 0.2s linear"
  57. e.qdata = {
  58. angle: Math.random() * 360,
  59. momentum: Math.random() * 10
  60. }
  61. e.qdata.lasttick = Date.now()
  62. })
  63.  
  64. function alltick() {
  65. requestAnimationFrame(alltick)
  66. qs.forEach((e) => tickq(e))
  67. }
  68.  
  69. alltick()