confettijs.org

Confetti generator

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/463384/1171662/confettijsorg.js

  1. // ==UserScript==
  2. // @name confettijs.org
  3. // @namespace https://confettijs.org/
  4. // @description Confetti generator
  5. // @version 1.0.0
  6. // @author Unknown
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. var Confetti = function() {
  11. var t = function() {
  12. return function() {
  13. this.gravity = 10, this.particle_count = 75, this.particle_size = 1, this.explosion_power = 25, this.destroy_target = !0, this.fade = !1
  14. }
  15. }(),
  16. e = function() {
  17. function e(n) {
  18. var r = this;
  19. if (this.bursts = [], this.setCount = function(t) {
  20. if ("number" != typeof t) throw new Error("Input must be of type 'number'");
  21. e.CONFIG.particle_count = t
  22. }, this.setPower = function(t) {
  23. if ("number" != typeof t) throw new Error("Input must be of type 'number'");
  24. e.CONFIG.explosion_power = t
  25. }, this.setSize = function(t) {
  26. if ("number" != typeof t) throw new Error("Input must be of type 'number'");
  27. e.CONFIG.particle_size = t
  28. }, this.setFade = function(t) {
  29. if ("boolean" != typeof t) throw new Error("Input must be of type 'boolean'");
  30. e.CONFIG.fade = t
  31. }, this.destroyTarget = function(t) {
  32. if ("boolean" != typeof t) throw new Error("Input must be of type 'boolean'");
  33. e.CONFIG.destroy_target = t
  34. }, this.setupCanvasContext = function() {
  35. if (!e.CTX) {
  36. var t = document.createElement("canvas");
  37. e.CTX = t.getContext("2d"), t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.style.position = "fixed", t.style.top = "0", t.style.left = "0", t.style.width = "calc(100%)", t.style.height = "calc(100%)", t.style.margin = "0", t.style.padding = "0", t.style.zIndex = "999999999", t.style.pointerEvents = "none", document.body.appendChild(t), window.addEventListener("resize", function() {
  38. t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight
  39. })
  40. }
  41. }, this.setupElement = function(t) {
  42. var n;
  43. r.element = document.getElementById(t), null === (n = r.element) || void 0 === n || n.addEventListener("click", function(t) {
  44. var n = new o(2 * t.clientX, 2 * t.clientY);
  45. r.bursts.push(new i(n)), e.CONFIG.destroy_target && (r.element.style.visibility = "hidden")
  46. })
  47. }, this.update = function(t) {
  48. r.delta_time = (t - r.time) / 1e3, r.time = t;
  49. for (var e = r.bursts.length - 1; e >= 0; e--) r.bursts[e].update(r.delta_time), 0 == r.bursts[e].particles.length && r.bursts.splice(e, 1);
  50. r.draw(), window.requestAnimationFrame(r.update)
  51. }, !n) throw new Error("Missing id");
  52. e.CONFIG || (e.CONFIG = new t), this.time = (new Date).getTime(), this.delta_time = 0, this.setupCanvasContext(), this.setupElement(n), window.requestAnimationFrame(this.update)
  53. }
  54. return e.prototype.draw = function() {
  55. s.clearScreen();
  56. for (var t = 0, e = this.bursts; t < e.length; t++) {
  57. e[t].draw()
  58. }
  59. }, e
  60. }(),
  61. i = function() {
  62. function t(t) {
  63. this.particles = [];
  64. for (var i = 0; i < e.CONFIG.particle_count; i++) this.particles.push(new n(t))
  65. }
  66. return t.prototype.update = function(t) {
  67. for (var e = this.particles.length - 1; e >= 0; e--) this.particles[e].update(t), this.particles[e].checkBounds() && this.particles.splice(e, 1)
  68. }, t.prototype.draw = function() {
  69. for (var t = this.particles.length - 1; t >= 0; t--) this.particles[t].draw()
  70. }, t
  71. }(),
  72. n = function() {
  73. function t(t) {
  74. this.size = new o((16 * Math.random() + 4) * e.CONFIG.particle_size, (4 * Math.random() + 4) * e.CONFIG.particle_size), this.position = new o(t.x - this.size.x / 2, t.y - this.size.y / 2), this.velocity = r.generateVelocity(), this.rotation = 360 * Math.random(), this.rotation_speed = 10 * (Math.random() - .5), this.hue = 360 * Math.random(), this.opacity = 100, this.lifetime = Math.random() + .25
  75. }
  76. return t.prototype.update = function(t) {
  77. this.velocity.y += e.CONFIG.gravity * (this.size.y / (10 * e.CONFIG.particle_size)) * t, this.velocity.x += 25 * (Math.random() - .5) * t, this.velocity.y *= .98, this.velocity.x *= .98, this.position.x += this.velocity.x, this.position.y += this.velocity.y, this.rotation += this.rotation_speed, e.CONFIG.fade && (this.opacity -= this.lifetime)
  78. }, t.prototype.checkBounds = function() {
  79. return this.position.y - 2 * this.size.x > 2 * window.innerHeight
  80. }, t.prototype.draw = function() {
  81. s.drawRectangle(this.position, this.size, this.rotation, this.hue, this.opacity)
  82. }, t
  83. }(),
  84. o = function() {
  85. return function(t, e) {
  86. this.x = t || 0, this.y = e || 0
  87. }
  88. }(),
  89. r = function() {
  90. function t() {}
  91. return t.generateVelocity = function() {
  92. var t = Math.random() - .5,
  93. i = Math.random() - .7,
  94. n = Math.sqrt(t * t + i * i);
  95. return i /= n, new o((t /= n) * (Math.random() * e.CONFIG.explosion_power), i * (Math.random() * e.CONFIG.explosion_power))
  96. }, t
  97. }(),
  98. s = function() {
  99. function t() {}
  100. return t.clearScreen = function() {
  101. e.CTX && e.CTX.clearRect(0, 0, 2 * window.innerWidth, 2 * window.innerHeight)
  102. }, t.drawRectangle = function(t, i, n, o, r) {
  103. e.CTX && (e.CTX.save(), e.CTX.beginPath(), e.CTX.translate(t.x + i.x / 2, t.y + i.y / 2), e.CTX.rotate(n * Math.PI / 180), e.CTX.rect(-i.x / 2, -i.y / 2, i.x, i.y), e.CTX.fillStyle = "hsla(" + o + "deg, 90%, 65%, " + r + "%)", e.CTX.fill(), e.CTX.restore())
  104. }, t
  105. }();
  106. return e
  107. }();

QingJ © 2025

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