Advertisement
Guest User

Bomb script:

a guest
Mar 5th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.   var Bomb, Explosion, Particle, targetTime, vendor, w, _i, _len, _ref,
  3.     __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  4.  
  5.   w = window;
  6.  
  7.   _ref = ['ms', 'moz', 'webkit', 'o'];
  8.   for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  9.     vendor = _ref[_i];
  10.     if (w.requestAnimationFrame) break;
  11.     w.requestAnimationFrame = w["#vendorRequestAnimationFrame"];
  12.     w.cancelAnimationFrame = w["#vendorCancelAnimationFrame"] || w["#vendorCancelRequestAnimationFrame"];
  13.   }
  14.  
  15.   targetTime = 0;
  16.  
  17.   w.requestAnimationFrame || (w.requestAnimationFrame = function(callback) {
  18.     var currentTime;
  19.     targetTime = Math.max(targetTime + 16, currentTime = +(new Date));
  20.     return w.setTimeout((function() {
  21.       return callback(+(new Date));
  22.     }), targetTime - currentTime);
  23.   });
  24.  
  25.   w.cancelAnimationFrame || (w.cancelAnimationFrame = function(id) {
  26.     return clearTimeout(id);
  27.   });
  28.  
  29.   w.findClickPos = function(e) {
  30.     var posx, posy;
  31.     posx = 0;
  32.     posy = 0;
  33.     if (!e) e = window.event;
  34.     if (e.pageX || e.pageY) {
  35.       posx = e.pageX;
  36.       posy = e.pageY;
  37.     } else if (e.clientX || e.clientY) {
  38.       posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
  39.       posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  40.     }
  41.     return {
  42.       x: posx,
  43.       y: posy
  44.     };
  45.   };
  46.  
  47.   w.getOffset = function(el) {
  48.     var body, _x, _y;
  49.     body = document.getElementsByTagName("body")[0];
  50.     _x = 0;
  51.     _y = 0;
  52.     while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
  53.       _x += el.offsetLeft - el.scrollLeft;
  54.       _y += el.offsetTop - el.scrollTop;
  55.       el = el.offsetParent;
  56.     }
  57.     return {
  58.       top: _y + body.scrollTop,
  59.       left: _x + body.scrollLeft
  60.     };
  61.   };
  62.  
  63.   Particle = (function() {
  64.  
  65.     function Particle(elem) {
  66.       this.elem = elem;
  67.       this.style = elem.style;
  68.       this.elem.style['zIndex'] = 9999;
  69.       this.transformX = 0;
  70.       this.transformY = 0;
  71.       this.transformRotation = 0;
  72.       this.offsetTop = window.getOffset(this.elem).top;
  73.       this.offsetLeft = window.getOffset(this.elem).left;
  74.       this.velocityX = 0;
  75.       this.velocityY = 0;
  76.     }
  77.  
  78.     Particle.prototype.tick = function(blast) {
  79.       var distX, distXS, distY, distYS, distanceWithBlast, force, forceX, forceY, previousRotation, previousStateX, previousStateY, rad, transform;
  80.       previousStateX = this.transformX;
  81.       previousStateY = this.transformY;
  82.       previousRotation = this.transformRotation;
  83.       if (this.velocityX > 1.5) {
  84.         this.velocityX -= 1.5;
  85.       } else if (this.velocityX < -1.5) {
  86.         this.velocityX += 1.5;
  87.       } else {
  88.         this.velocityX = 0;
  89.       }
  90.       if (this.velocityY > 1.5) {
  91.         this.velocityY -= 1.5;
  92.       } else if (this.velocityY < -1.5) {
  93.         this.velocityY += 1.5;
  94.       } else {
  95.         this.velocityY = 0;
  96.       }
  97.       if (blast != null) {
  98.         distX = this.offsetLeft + this.transformX - blast.x;
  99.         distY = this.offsetTop + this.transformY - blast.y;
  100.         distXS = distX * distX;
  101.         distYS = distY * distY;
  102.         distanceWithBlast = distXS + distYS;
  103.         force = 100000 / distanceWithBlast;
  104.         if (force > 50) force = 50;
  105.         rad = Math.asin(distYS / distanceWithBlast);
  106.         forceY = Math.sin(rad) * force * (distY < 0 ? -1 : 1);
  107.         forceX = Math.cos(rad) * force * (distX < 0 ? -1 : 1);
  108.         this.velocityX = +forceX;
  109.         this.velocityY = +forceY;
  110.       }
  111.       this.transformX = this.transformX + this.velocityX;
  112.       this.transformY = this.transformY + this.velocityY;
  113.       this.transformRotation = this.transformX * -1;
  114.       if ((Math.abs(previousStateX - this.transformX) > 1 || Math.abs(previousStateY - this.transformY) > 1 || Math.abs(previousRotation - this.transformRotation) > 1) && ((this.transformX > 1 || this.transformX < -1) || (this.transformY > 1 || this.transformY < -1))) {
  115.         transform = "translate(" + this.transformX + "px, " + this.transformY + "px) rotate(" + this.transformRotation + "deg)";
  116.         this.style['MozTransform'] = transform;
  117.         this.style['OTransform'] = transform;
  118.         this.style['WebkitTransform'] = transform;
  119.         this.style['msTransform'] = transform;
  120.         return this.style['transform'] = transform;
  121.       }
  122.     };
  123.  
  124.     return Particle;
  125.  
  126.   })();
  127.  
  128.   this.Particle = Particle;
  129.  
  130.   Bomb = (function() {
  131.  
  132.     Bomb.SIZE = 50;
  133.  
  134.     function Bomb(x, y) {
  135.       this.countDown = __bind(this.countDown, this);
  136.       this.drop = __bind(this.drop, this);      this.pos = {
  137.         x: x,
  138.         y: y
  139.       };
  140.       this.body = document.getElementsByTagName("body")[0];
  141.       this.state = 'planted';
  142.       this.count = 3;
  143.       this.drop();
  144.     }
  145.  
  146.     Bomb.prototype.drop = function() {
  147.       this.bomb = document.createElement("div");
  148.       this.bomb.innerHTML = this.count;
  149.       this.body.appendChild(this.bomb);
  150.       this.bomb.style['zIndex'] = "9999";
  151.       this.bomb.style['fontFamily'] = "verdana";
  152.       this.bomb.style['width'] = "" + Bomb.SIZE + "px";
  153.       this.bomb.style['height'] = "" + Bomb.SIZE + "px";
  154.       this.bomb.style['display'] = 'block';
  155.       this.bomb.style['borderRadius'] = "" + Bomb.SIZE + "px";
  156.       this.bomb.style['WebkitBorderRadius'] = "" + Bomb.SIZE + "px";
  157.       this.bomb.style['MozBorderRadius'] = "" + Bomb.SIZE + "px";
  158.       this.bomb.style['fontSize'] = '18px';
  159.       this.bomb.style['color'] = '#fff';
  160.       this.bomb.style['lineHeight'] = "" + Bomb.SIZE + "px";
  161.       this.bomb.style['background'] = '#000';
  162.       this.bomb.style['position'] = 'absolute';
  163.       this.bomb.style['top'] = "" + (this.pos.y - Bomb.SIZE / 2) + "px";
  164.       this.bomb.style['left'] = "" + (this.pos.x - Bomb.SIZE / 2) + "px";
  165.       this.bomb.style['textAlign'] = "center";
  166.       this.bomb.style['WebkitUserSelect'] = 'none';
  167.       this.bomb.style['font-weight'] = 700;
  168.       return setTimeout(this.countDown, 1000);
  169.     };
  170.  
  171.     Bomb.prototype.countDown = function() {
  172.       this.state = 'ticking';
  173.       this.count--;
  174.       this.bomb.innerHTML = this.count;
  175.       if (this.count > 0) {
  176.         return setTimeout(this.countDown, 1000);
  177.       } else {
  178.         return this.explose();
  179.       }
  180.     };
  181.  
  182.     Bomb.prototype.explose = function() {
  183.       this.bomb.innerHTML = '';
  184.       return this.state = 'explose';
  185.     };
  186.  
  187.     Bomb.prototype.exploded = function() {
  188.       this.state = 'exploded';
  189.       this.bomb.innerHTML = '';
  190.       this.bomb.style['fontSize'] = '12px';
  191.       return this.bomb.style['opacity'] = 0.05;
  192.     };
  193.  
  194.     return Bomb;
  195.  
  196.   })();
  197.  
  198.   this.Bomb = Bomb;
  199.  
  200.   Explosion = (function() {
  201.  
  202.     function Explosion() {
  203.       this.tick = __bind(this.tick, this);
  204.       this.dropBomb = __bind(this.dropBomb, this);
  205.       var char, confirmation, style, _ref2,
  206.         _this = this;
  207.       if (window.FONTBOMB_LOADED) return;
  208.       window.FONTBOMB_LOADED = true;
  209.       if (!window.FONTBOMB_HIDE_CONFIRMATION) confirmation = true;
  210.       this.bombs = [];
  211.       this.body = document.getElementsByTagName("body")[0];
  212.       if ((_ref2 = this.body) != null) {
  213.         _ref2.onclick = function(event) {
  214.           return _this.dropBomb(event);
  215.         };
  216.       }
  217.       this.body.addEventListener("touchstart", function(event) {
  218.         return _this.touchEvent = event;
  219.       });
  220.       this.body.addEventListener("touchmove", function(event) {
  221.         _this.touchMoveCount || (_this.touchMoveCount = 0);
  222.         return _this.touchMoveCount++;
  223.       });
  224.       this.body.addEventListener("touchend", function(event) {
  225.         if (_this.touchMoveCount < 2) _this.dropBomb(_this.touchEvent);
  226.         return _this.touchMoveCount = 0;
  227.       });
  228.       this.explosifyNodes(this.body.childNodes);
  229.       this.chars = (function() {
  230.         var _j, _len2, _ref3, _results;
  231.         _ref3 = document.getElementsByTagName('particle');
  232.         _results = [];
  233.         for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
  234.           char = _ref3[_j];
  235.           _results.push(new Particle(char, this.body));
  236.         }
  237.         return _results;
  238.       }).call(this);
  239.       this.tick();
  240.       if (confirmation != null) {
  241.         style = document.createElement('style');
  242.         style.innerHTML = "div#fontBombConfirmation {\n  position: absolute;\n  top: -200px;\n  left: 0px;\n  right: 0px;\n  bottom: none;\n  width: 100%;\n  padding: 18px;\n  margin: 0px;\n  background: #e8e8e8;\n  text-align: center;\n  font-size: 14px;\n  line-height: 14px;\n  font-family: verdana, sans-serif;\n  color: #000;\n  -webkit-transition: all 1s ease-in-out;\n  -moz-transition: all 1s ease-in-out;\n  -o-transition: all 1s ease-in-out;\n  -ms-transition: all 1s ease-in-out;\n  transition: all 1s ease-in-out;\n  -webkit-box-shadow: 0px 3px 3px rgba(0,0,0,0.20);\n  -moz-box-shadow: 0px 3px 3px rgba(0,0,0,0.20);\n  box-shadow: 0px 3px 3px rgba(0,0,0,0.20);\n  z-index: 100000002;\n}\ndiv#fontBombConfirmation span,div#fontBombConfirmation a {\n  color: #fe3a1a;\n}\ndiv#fontBombConfirmation.show {\n  top:0px;\n  display:block;\n}";
  243.         document.head.appendChild(style);
  244.         this.confirmation = document.createElement("div");
  245.         this.confirmation.id = 'fontBombConfirmation';
  246.         this.confirmation.innerHTML = "<span style='font-weight:bold;'>Te koop voor 40 Cent!</span> Made by: KURSAD " + (document.title.substring(0, 50));
  247.         this.body.appendChild(this.confirmation);
  248.         setTimeout(function() {
  249.           return _this.confirmation.className = 'show';
  250.         }, 10);
  251.         setTimeout(function() {
  252.           _this.confirmation.className = '';
  253.           return setTimeout(function() {
  254.             _this.confirmation.innerHTML = "Onthoud kids: Cool is niet altijd cool!";
  255.             _this.confirmation.className = 'show';
  256.             return setTimeout(function() {
  257.               return _this.confirmation.className = '';
  258.             }, 20000);
  259.           }, 5000);
  260.         }, 5000);
  261.       }
  262.     }
  263.  
  264.     Explosion.prototype.explosifyNodes = function(nodes) {
  265.       var node, _j, _len2, _results;
  266.       _results = [];
  267.       for (_j = 0, _len2 = nodes.length; _j < _len2; _j++) {
  268.         node = nodes[_j];
  269.         _results.push(this.explosifyNode(node));
  270.       }
  271.       return _results;
  272.     };
  273.  
  274.     Explosion.prototype.explosifyNode = function(node) {
  275.       var name, newNode, _j, _len2, _ref2;
  276.       _ref2 = ['script', 'style', 'iframe', 'canvas', 'video', 'audio', 'textarea', 'embed', 'object', 'select', 'area', 'map', 'input'];
  277.       for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
  278.         name = _ref2[_j];
  279.         if (node.nodeName.toLowerCase() === name) return;
  280.       }
  281.       switch (node.nodeType) {
  282.         case 1:
  283.           return this.explosifyNodes(node.childNodes);
  284.         case 3:
  285.           if (!/^\s*$/.test(node.nodeValue)) {
  286.             if (node.parentNode.childNodes.length === 1) {
  287.               return node.parentNode.innerHTML = this.explosifyText(node.nodeValue);
  288.             } else {
  289.               newNode = document.createElement("particles");
  290.               newNode.innerHTML = this.explosifyText(node.nodeValue);
  291.               return node.parentNode.replaceChild(newNode, node);
  292.             }
  293.           }
  294.       }
  295.     };
  296.  
  297.     Explosion.prototype.explosifyText = function(string) {
  298.       var char, chars, index;
  299.       chars = (function() {
  300.         var _len2, _ref2, _results;
  301.         _ref2 = string.split('');
  302.         _results = [];
  303.         for (index = 0, _len2 = _ref2.length; index < _len2; index++) {
  304.           char = _ref2[index];
  305.           if (!/^\s*$/.test(char)) {
  306.             _results.push("<particle style='display:inline-block;'>" + char + "</particle>");
  307.           } else {
  308.             _results.push('&nbsp;');
  309.           }
  310.         }
  311.         return _results;
  312.       })();
  313.       chars = chars.join('');
  314.       chars = (function() {
  315.         var _len2, _ref2, _results;
  316.         _ref2 = chars.split('&nbsp;');
  317.         _results = [];
  318.         for (index = 0, _len2 = _ref2.length; index < _len2; index++) {
  319.           char = _ref2[index];
  320.           if (!/^\s*$/.test(char)) {
  321.             _results.push("<word style='white-space:nowrap'>" + char + "</word>");
  322.           } else {
  323.             _results.push(char);
  324.           }
  325.         }
  326.         return _results;
  327.       })();
  328.       return chars.join(' ');
  329.     };
  330.  
  331.     Explosion.prototype.dropBomb = function(event) {
  332.       var pos;
  333.       pos = window.findClickPos(event);
  334.       this.bombs.push(new Bomb(pos.x, pos.y));
  335.       if (window.FONTBOMB_PREVENT_DEFAULT) return event.preventDefault();
  336.     };
  337.  
  338.     Explosion.prototype.tick = function() {
  339.       var bomb, char, _j, _k, _l, _len2, _len3, _len4, _ref2, _ref3, _ref4;
  340.       _ref2 = this.bombs;
  341.       for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
  342.         bomb = _ref2[_j];
  343.         if (bomb.state === 'explose') {
  344.           bomb.exploded();
  345.           this.blast = bomb.pos;
  346.         }
  347.       }
  348.       if (this.blast != null) {
  349.         _ref3 = this.chars;
  350.         for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
  351.           char = _ref3[_k];
  352.           char.tick(this.blast);
  353.         }
  354.         this.blast = null;
  355.       } else {
  356.         _ref4 = this.chars;
  357.         for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) {
  358.           char = _ref4[_l];
  359.           char.tick();
  360.         }
  361.       }
  362.       return requestAnimationFrame(this.tick);
  363.     };
  364.  
  365.     return Explosion;
  366.  
  367.   })();
  368.  
  369.   new Explosion();
  370.  
  371. }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement