🏠 Home 

confettijs.org

Confetti generator

Этот скрипт недоступен для установки пользователем. Он является библиотекой, которая подключается к другим скриптам мета-ключом // @require https://update.greasyfork.org/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. var Confetti = function() {
  10. var t = function() {
  11. return function() {
  12. this.gravity = 10, this.particle_count = 75, this.particle_size = 1, this.explosion_power = 25, this.destroy_target = !0, this.fade = !1
  13. }
  14. }(),
  15. e = function() {
  16. function e(n) {
  17. var r = this;
  18. if (this.bursts = [], this.setCount = function(t) {
  19. if ("number" != typeof t) throw new Error("Input must be of type 'number'");
  20. e.CONFIG.particle_count = t
  21. }, this.setPower = function(t) {
  22. if ("number" != typeof t) throw new Error("Input must be of type 'number'");
  23. e.CONFIG.explosion_power = t
  24. }, this.setSize = function(t) {
  25. if ("number" != typeof t) throw new Error("Input must be of type 'number'");
  26. e.CONFIG.particle_size = t
  27. }, this.setFade = function(t) {
  28. if ("boolean" != typeof t) throw new Error("Input must be of type 'boolean'");
  29. e.CONFIG.fade = t
  30. }, this.destroyTarget = function(t) {
  31. if ("boolean" != typeof t) throw new Error("Input must be of type 'boolean'");
  32. e.CONFIG.destroy_target = t
  33. }, this.setupCanvasContext = function() {
  34. if (!e.CTX) {
  35. var t = document.createElement("canvas");
  36. 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() {
  37. t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight
  38. })
  39. }
  40. }, this.setupElement = function(t) {
  41. var n;
  42. r.element = document.getElementById(t), null === (n = r.element) || void 0 === n || n.addEventListener("click", function(t) {
  43. var n = new o(2 * t.clientX, 2 * t.clientY);
  44. r.bursts.push(new i(n)), e.CONFIG.destroy_target && (r.element.style.visibility = "hidden")
  45. })
  46. }, this.update = function(t) {
  47. r.delta_time = (t - r.time) / 1e3, r.time = t;
  48. 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);
  49. r.draw(), window.requestAnimationFrame(r.update)
  50. }, !n) throw new Error("Missing id");
  51. e.CONFIG || (e.CONFIG = new t), this.time = (new Date).getTime(), this.delta_time = 0, this.setupCanvasContext(), this.setupElement(n), window.requestAnimationFrame(this.update)
  52. }
  53. return e.prototype.draw = function() {
  54. s.clearScreen();
  55. for (var t = 0, e = this.bursts; t < e.length; t++) {
  56. e[t].draw()
  57. }
  58. }, e
  59. }(),
  60. i = function() {
  61. function t(t) {
  62. this.particles = [];
  63. for (var i = 0; i < e.CONFIG.particle_count; i++) this.particles.push(new n(t))
  64. }
  65. return t.prototype.update = function(t) {
  66. for (var e = this.particles.length - 1; e >= 0; e--) this.particles[e].update(t), this.particles[e].checkBounds() && this.particles.splice(e, 1)
  67. }, t.prototype.draw = function() {
  68. for (var t = this.particles.length - 1; t >= 0; t--) this.particles[t].draw()
  69. }, t
  70. }(),
  71. n = function() {
  72. function t(t) {
  73. 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
  74. }
  75. return t.prototype.update = function(t) {
  76. 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)
  77. }, t.prototype.checkBounds = function() {
  78. return this.position.y - 2 * this.size.x > 2 * window.innerHeight
  79. }, t.prototype.draw = function() {
  80. s.drawRectangle(this.position, this.size, this.rotation, this.hue, this.opacity)
  81. }, t
  82. }(),
  83. o = function() {
  84. return function(t, e) {
  85. this.x = t || 0, this.y = e || 0
  86. }
  87. }(),
  88. r = function() {
  89. function t() {}
  90. return t.generateVelocity = function() {
  91. var t = Math.random() - .5,
  92. i = Math.random() - .7,
  93. n = Math.sqrt(t * t + i * i);
  94. return i /= n, new o((t /= n) * (Math.random() * e.CONFIG.explosion_power), i * (Math.random() * e.CONFIG.explosion_power))
  95. }, t
  96. }(),
  97. s = function() {
  98. function t() {}
  99. return t.clearScreen = function() {
  100. e.CTX && e.CTX.clearRect(0, 0, 2 * window.innerWidth, 2 * window.innerHeight)
  101. }, t.drawRectangle = function(t, i, n, o, r) {
  102. 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())
  103. }, t
  104. }();
  105. return e
  106. }();