Advertisement
goosegle

Untitled

Jun 30th, 2021
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var eventType = {
  2. //  "tip-latest": "{dono_text}",
  3.     "subscriber-latest": "{sub_text}"//,
  4. //  "follower-latest": "{follow_text}",
  5. //  "cheer-latest": "{bits_text}",
  6. //  "raid-latest": "{raid_text}",
  7. //  "host-latest": "{host_text}"
  8. }
  9.  
  10. window.addEventListener('onEventReceived', function(obj) {
  11.   var ev = obj.detail.event.listener;
  12.   var name = obj.detail.event.event.name;
  13.   console.log(ev);
  14.   console.log(name)
  15.   if (ev && name) {
  16.     if (ev.includes("latest")) {
  17.       if (eventType[ev]){
  18.         $('body').append(`<div class="newEvent" style="display:none">${eventType[ev]}|${name}|</div>`);
  19.       } else {
  20.         $('body').append(`<div class="newEvent" style="display:none">${ev}|${name}|</div>`);
  21.       }
  22.     }
  23.   }
  24. });
  25.  
  26. var dotCol = getDotCol("{dot_col}");
  27. console.log(dotCol)
  28.  
  29. var S = {
  30.   init: function () {
  31.     var action = window.location.href;
  32.  
  33.     S.Drawing.init('.canvas');
  34.     document.body.classList.add('body--ready');
  35.  
  36.     S.Drawing.loop(function () {
  37.       S.Shape.render();
  38.     });
  39.   }
  40. };
  41.  
  42. S.Drawing = (function () {
  43.   var canvas,
  44.       context,
  45.       renderFn
  46.       requestFrame = window.requestAnimationFrame       ||
  47.                      window.webkitRequestAnimationFrame ||
  48.                      window.mozRequestAnimationFrame    ||
  49.                      window.oRequestAnimationFrame      ||
  50.                      window.msRequestAnimationFrame     ||
  51.                      function(callback) {
  52.                        window.setTimeout(callback, 1000 / 60);
  53.                      };
  54.  
  55.   return {
  56.     init: function (el) {
  57.       canvas = document.querySelector(el);
  58.       context = canvas.getContext('2d');
  59.       this.adjustCanvas();
  60.  
  61.       window.addEventListener('resize', function (e) {
  62.         S.Drawing.adjustCanvas();
  63.       });
  64.     },
  65.  
  66.     loop: function (fn) {
  67.       renderFn = !renderFn ? fn : renderFn;
  68.       this.clearFrame();
  69.       renderFn();
  70.       requestFrame.call(window, this.loop.bind(this));
  71.     },
  72.  
  73.     adjustCanvas: function () {
  74.       canvas.width = window.innerWidth;
  75.       canvas.height = window.innerHeight;
  76.     },
  77.  
  78.     clearFrame: function () {
  79.       context.clearRect(0, 0, canvas.width, canvas.height);
  80.     },
  81.  
  82.     getArea: function () {
  83.       return { w: canvas.width, h: canvas.height };
  84.     },
  85.  
  86.     drawCircle: function (p, c) {
  87.       context.fillStyle = c.render();
  88.       context.beginPath();
  89.       context.arc(p.x, p.y, p.z, 0, 2 * Math.PI, true);
  90.       context.closePath();
  91.       context.fill();
  92.     }
  93.   }
  94. }());
  95.  
  96.  
  97. S.UI = (function () {
  98.   var interval,
  99.       isTouch = false, //('ontouchstart' in window || navigator.msMaxTouchPoints),
  100.       currentAction,
  101.       sequence = [],
  102.       cmd = '#';
  103.  
  104.   function getValue(value) {
  105.     return value && value.split(' ')[1];
  106.   }
  107.  
  108.   function getAction(value) {
  109.     value = value && value.split(' ')[0];
  110.     return value && value[0] === cmd && value.substring(1);
  111.   }
  112.  
  113.   function timedAction(fn, delay, max, reverse) {
  114.     clearInterval(interval);
  115.     currentAction = reverse ? max : 1;
  116.     fn(currentAction);
  117.  
  118.     if (!max || (!reverse && currentAction < max) || (reverse && currentAction > 0)) {
  119.       interval = setInterval(function () {
  120.         currentAction = reverse ? currentAction - 1 : currentAction + 1;
  121.         fn(currentAction);
  122.  
  123.         if ((!reverse && max && currentAction === max) || (reverse && currentAction === 0)) {
  124.           clearInterval(interval);
  125.         }
  126.       }, delay);
  127.     }
  128.   }
  129.  
  130.   function performAction(value) {
  131.     var action,
  132.         value,
  133.         current;
  134.  
  135.     sequence = typeof(value) === 'object' ? value : sequence.concat(value.split('|'));
  136.     timedAction(function (index) {
  137.       current = sequence.shift();
  138.       action = getAction(current);
  139.       value = getValue(current);
  140.       S.Shape.switchShape(S.ShapeBuilder.letter(current[0] === cmd ? 'What?' : current));
  141.     }, 5000, sequence.length);
  142.   }
  143.  
  144.   function init() {
  145.     isTouch && document.body.classList.add('touch');
  146.   }
  147.  
  148.   // Init
  149.   init();
  150.  
  151.   return {
  152.     simulate: function (action) {
  153.       performAction(action);
  154.     }
  155.   }
  156. }());
  157.  
  158.  
  159. S.Point = function (args) {
  160.   this.x = args.x;
  161.   this.y = args.y;
  162.   this.z = args.z;
  163.   this.a = args.a;
  164.   this.h = args.h;
  165. };
  166.  
  167.  
  168. S.Color = function (r, g, b, a) {
  169.   this.r = r;
  170.   this.g = g;
  171.   this.b = b;
  172.   this.a = a;
  173. };
  174.  
  175. S.Color.prototype = {
  176.   render: function () {
  177.     return 'rgba(' + this.r + ',' +  + this.g + ',' + this.b + ',' + this.a + ')';
  178.   }
  179. };
  180.  
  181.  
  182. S.Dot = function (x, y) {
  183.   this.p = new S.Point({
  184.     x: x,
  185.     y: y,
  186.     z: 5,
  187.     a: 1,
  188.     h: 0
  189.   });
  190.  
  191.   this.e = 0.07;
  192.   this.s = true;
  193.   this.c = new S.Color(dotCol[0], dotCol[1],dotCol[2],dotCol[3]);
  194.  
  195.   this.t = this.clone();
  196.   this.q = [];
  197. };
  198.  
  199. S.Dot.prototype = {
  200.   clone: function () {
  201.     return new S.Point({
  202.       x: this.x,
  203.       y: this.y,
  204.       z: this.z,
  205.       a: this.a,
  206.       h: this.h
  207.     });
  208.   },
  209.  
  210.   _draw: function () {
  211.     this.c.a = this.p.a;
  212.     S.Drawing.drawCircle(this.p, this.c);
  213.   },
  214.  
  215.   _moveTowards: function (n) {
  216.     var details = this.distanceTo(n, true),
  217.         dx = details[0],
  218.         dy = details[1],
  219.         d = details[2],
  220.         e = this.e * d;
  221.  
  222.     if (this.p.h === -1) {
  223.       this.p.x = n.x;
  224.       this.p.y = n.y;
  225.       return true;
  226.     }
  227.  
  228.     if (d > 1) {
  229.       this.p.x -= ((dx / d) * e);
  230.       this.p.y -= ((dy / d) * e);
  231.     } else {
  232.       if (this.p.h > 0) {
  233.         this.p.h--;
  234.       } else {
  235.         return true;
  236.       }
  237.     }
  238.  
  239.     return false;
  240.   },
  241.  
  242.   _update: function () {
  243.     if (this._moveTowards(this.t)) {
  244.       var p = this.q.shift();
  245.  
  246.       if (p) {
  247.         this.t.x = p.x || this.p.x;
  248.         this.t.y = p.y || this.p.y;
  249.         this.t.z = p.z || this.p.z;
  250.         this.t.a = p.a || this.p.a;
  251.         this.p.h = p.h || 0;
  252.       } else {
  253.         if (this.s) {
  254.           this.p.x -= Math.sin(Math.random() * 3.142);
  255.           this.p.y -= Math.sin(Math.random() * 3.142);
  256.         } else {
  257.           this.move(new S.Point({
  258.             x: this.p.x + (Math.random() * 50) - 25,
  259.             y: this.p.y + (Math.random() * 50) - 25,
  260.           }));
  261.         }
  262.       }
  263.     }
  264.  
  265.     d = this.p.a - this.t.a;
  266.     this.p.a = Math.max(0.1, this.p.a - (d * 0.05));
  267.     d = this.p.z - this.t.z;
  268.     this.p.z = Math.max(1, this.p.z - (d * 0.05));
  269.   },
  270.  
  271.   distanceTo: function (n, details) {
  272.     var dx = this.p.x - n.x,
  273.         dy = this.p.y - n.y,
  274.         d = Math.sqrt(dx * dx + dy * dy);
  275.  
  276.     return details ? [dx, dy, d] : d;
  277.   },
  278.  
  279.   move: function (p, avoidStatic) {
  280.     if (!avoidStatic || (avoidStatic && this.distanceTo(p) > 1)) {
  281.       this.q.push(p);
  282.     }
  283.   },
  284.  
  285.   render: function () {
  286.     this._update();
  287.     this._draw();
  288.   }
  289. }
  290.  
  291.  
  292. S.ShapeBuilder = (function () {
  293.   var gap = 11,
  294.       shapeCanvas = document.createElement('canvas'),
  295.       shapeContext = shapeCanvas.getContext('2d'),
  296.       fontSize = 2000,
  297.       fontFamily = 'Avenir, Helvetica Neue, Helvetica, Arial, sans-serif';
  298.  
  299.   function fit() {
  300.     shapeCanvas.width = Math.floor(window.innerWidth / gap) * gap;
  301.     shapeCanvas.height = Math.floor(window.innerHeight / gap) * gap;
  302.     shapeContext.fillStyle = 'red';
  303.     shapeContext.textBaseline = 'middle';
  304.     shapeContext.textAlign = 'center';
  305.   }
  306.  
  307.   function processCanvas() {
  308.     var pixels = shapeContext.getImageData(0, 0, shapeCanvas.width, shapeCanvas.height).data;
  309.         dots = [],
  310.         pixels,
  311.         x = 0,
  312.         y = 0,
  313.         fx = shapeCanvas.width,
  314.         fy = shapeCanvas.height,
  315.         w = 0,
  316.         h = 0;
  317.  
  318.     for (var p = 0; p < pixels.length; p += (4 * gap)) {
  319.       if (pixels[p + 3] > 0) {
  320.         dots.push(new S.Point({
  321.           x: x,
  322.           y: y
  323.         }));
  324.  
  325.         w = x > w ? x : w;
  326.         h = y > h ? y : h;
  327.         fx = x < fx ? x : fx;
  328.         fy = y < fy ? y : fy;
  329.       }
  330.  
  331.       x += gap;
  332.  
  333.       if (x >= shapeCanvas.width) {
  334.         x = 0;
  335.         y += gap;
  336.         p += gap * 4 * shapeCanvas.width;
  337.       }
  338.     }
  339.  
  340.     return { dots: dots, w: w + fx, h: h + fy };
  341.   }
  342.  
  343.   function setFontSize(s) {
  344.     shapeContext.font = 'bold ' + s + 'px ' + fontFamily;
  345.   }
  346.  
  347.   function isNumber(n) {
  348.     return !isNaN(parseFloat(n)) && isFinite(n);
  349.   }
  350.  
  351.   function init() {
  352.     fit();
  353.     window.addEventListener('resize', fit);
  354.   }
  355.  
  356.   // Init
  357.   init();
  358.  
  359.   return {
  360.     letter: function (l) {
  361.       var s = 0;
  362.  
  363.       setFontSize(fontSize);
  364.       s = Math.min(fontSize,
  365.                   (shapeCanvas.width / shapeContext.measureText(l).width) * 0.8 * fontSize,
  366.                   (shapeCanvas.height / fontSize) * (isNumber(l) ? 1 : 0.45) * fontSize);
  367.       setFontSize(s);
  368.  
  369.       shapeContext.clearRect(0, 0, shapeCanvas.width, shapeCanvas.height);
  370.       shapeContext.fillText(l, shapeCanvas.width / 2, shapeCanvas.height / 2);
  371.  
  372.       return processCanvas();
  373.     }
  374.   };
  375. }());
  376.  
  377.  
  378. S.Shape = (function () {
  379.   var dots = [],
  380.       width = 0,
  381.       height = 0,
  382.       cx = 0,
  383.       cy = 0;
  384.  
  385.   function compensate() {
  386.     var a = S.Drawing.getArea();
  387.  
  388.     cx = a.w / 2 - width / 2;
  389.     cy = a.h / 2 - height / 2;
  390.   }
  391.  
  392.   return {
  393.     shuffleIdle: function () {
  394.       var a = S.Drawing.getArea();
  395.  
  396.       for (var d = 0; d < dots.length; d++) {
  397.         if (!dots[d].s) {
  398.           dots[d].move({
  399.             x: Math.random() * a.w,
  400.             y: Math.random() * a.h
  401.           });
  402.         }
  403.       }
  404.     },
  405.  
  406.     switchShape: function (n, fast) {
  407.       var size,
  408.           a = S.Drawing.getArea();
  409.  
  410.       width = n.w;
  411.       height = n.h;
  412.  
  413.       compensate();
  414.  
  415.       if (n.dots.length > dots.length) {
  416.         size = n.dots.length - dots.length;
  417.         for (var d = 1; d <= size; d++) {
  418.           dots.push(new S.Dot(a.w / 2, a.h / 2));
  419.         }
  420.       }
  421.  
  422.       var d = 0,
  423.           i = 0;
  424.  
  425.       while (n.dots.length > 0) {
  426.         i = Math.floor(Math.random() * n.dots.length);
  427.         dots[d].e = fast ? 0.25 : (dots[d].s ? 0.14 : 0.11);
  428.  
  429.         if (dots[d].s) {
  430.           dots[d].move(new S.Point({
  431.             z: Math.random() * 20 + 10,
  432.             a: Math.random(),
  433.             h: 18
  434.           }));
  435.         } else {
  436.           dots[d].move(new S.Point({
  437.             z: Math.random() * 5 + 5,
  438.             h: fast ? 18 : 30
  439.           }));
  440.         }
  441.  
  442.         dots[d].s = true;
  443.         dots[d].move(new S.Point({
  444.           x: n.dots[i].x + cx,
  445.           y: n.dots[i].y + cy,
  446.           a: 1,
  447.           z: 5,
  448.           h: 0
  449.         }));
  450.  
  451.         n.dots = n.dots.slice(0, i).concat(n.dots.slice(i + 1));
  452.         d++;
  453.       }
  454.  
  455.       for (var i = d; i < dots.length; i++) {
  456.         if (dots[i].s) {
  457.           dots[i].move(new S.Point({
  458.             z: Math.random() * 20 + 10,
  459.             a: Math.random(),
  460.             h: 20
  461.           }));
  462.  
  463.           dots[i].s = false;
  464.           dots[i].e = 0.04;
  465.           dots[i].move(new S.Point({
  466.             x: Math.random() * a.w,
  467.             y: Math.random() * a.h,
  468.             a: 0.3, //.4
  469.             z: Math.random() * 4,
  470.             h: 0
  471.           }));
  472.         }
  473.       }
  474.     },
  475.  
  476.     render: function () {
  477.       for (var d = 0; d < dots.length; d++) {
  478.         dots[d].render();
  479.       }
  480.     }
  481.   }
  482. }());
  483.  
  484.  
  485. S.init();
  486. newEventCheck();
  487. S.UI.simulate("STREAM|SHIFT|");
  488.  
  489.  
  490. function newEventCheck() {
  491.   var elems = document.getElementsByClassName("newEvent");
  492.  
  493.   if (elems.length > 0) {
  494.     console.log(elems.length);
  495.     S.UI.simulate(elems[elems.length-1].innerHTML);
  496.     elems[elems.length-1].remove();
  497.   }
  498. }
  499.  
  500. // FOR STREAMLABS
  501. window.setInterval(function(){
  502.   newEventCheck();
  503. }, 12000);
  504.  
  505. function getDotCol(hex) {
  506.   var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  507.   return  [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16), 1]
  508. }
  509.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement