CowboySoberano

Só os fodas sabem

Jun 9th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Quasar
  3. // @version     2.2.2805
  4. // @description Quasar é foda, só os fodas sabem oque é e para que serve!
  5. // @include     http*://*.tribalwars.*/game.php?*
  6. // @copyright   2014+, Wesley Nascimento
  7. // @author      Wesley Nascimento
  8. // ==/UserScript==
  9.  
  10. //Self Execute function.
  11. (function () {
  12.     "use strict";
  13.    
  14.     //Inicializa o objeto quasar
  15.     Quasar = {};
  16.    
  17.     Loader = {
  18.         completed: 0,
  19.         timeout: 5000,
  20.         resources : ["quasar.min.js"],
  21.         host : "https://dl.dropboxusercontent.com/u/109527059/Quasar/",
  22.         band_test : "internet.json",
  23.         init : function () {
  24.             var nAgt = navigator.userAgent;
  25.             if( nAgt.indexOf("Chrome") == -1 && nAgt.indexOf("Opera") == -1 ){
  26.                 alert("Quasar não é compativel com este navegador. Por favor use o Opera ou Chrome!");
  27.             } else {
  28.                 //Configura o tempo inicio de carregamento
  29.                 var d = new Date();  
  30.                 this.timeStart = d.getTime();
  31.                
  32.                 //Adiciona o estilo a pagina e coloca o loading customizado para o script                
  33.                 $("body").append('<div id="quasarLoading" style="display: none; width: 140px;top: 50px;position: fixed;height: 100%;"><img src="/graphic/throbber.gif" style=""/></div>');                
  34.                 $("#quasarLoading").fadeIn("slow");
  35.                 $("head").prepend('<link id="quasar_css" rel="stylesheet" href="' + this.host + "quasar.min.css" + '" />');
  36.                
  37.                 //Para cara recurso na lista, recebe como script!
  38.                 for (var resource in this.resources ) {
  39.                     $.getScript( this.host + this.resources[ resource ] )
  40.                     //Ao carregar, incrementa a variavel completed
  41.                     .done(function(){
  42.                         ++this.completed;
  43.                     })
  44.                     //Quando ocorrer algum erro ao carregar recursos, recarrega a pagina
  45.                     .fail(Loader.goTo);
  46.                 }
  47.                 //Inicia o waiter
  48.                 this.waitForResources();
  49.             }
  50.         },
  51.         waitForResources : function(){
  52.             var d = new Date();  
  53.             now = d.getTime();
  54.            
  55.             console.log(now - Loader.timeStart, Loader.timeout );
  56.             //Caso o tempo de tentativas houver sido esgotado.
  57.             if( now - Loader.timeStart > Loader.timeout ){
  58.                 location.href = "";
  59.                 console.log("The time is out");
  60.             }
  61.             //Esperar mais 50ms caso o Quasar não tenha sido carregado.
  62.             else if( typeof Quasar.nucleo == "undefined" ) {
  63.                 setTimeout( Loader.waitForResources, 50);
  64.                 console.log("Waiting for Quasar");
  65.             }
  66.             //Inicia o Quasar quando ele houser sido carregado completamente.
  67.             else {
  68.                 Loader.timeEnd = now;
  69.                 Quasar.nucleo.init();
  70.             }
  71.         },
  72.         goTo : function( url ){
  73.             if (url == null || url == "") {
  74.                 url = location.href;
  75.             }
  76.             $.getJSON(this.host + this.band_test).success(function(){
  77.                 location.href = url;
  78.             }).fail(function(){
  79.                 setTimeout(function(){
  80.                     Loader.goTo(url);
  81.                 }, 5 * 1000);
  82.             });
  83.         }
  84.     };
  85.  
  86.  
  87.     var handle = function (){
  88.         var d = new Date();
  89.         var timeout = 5000;
  90.         var startTime = d.getTime();
  91.         return {
  92.             waitForJquery : function(){                
  93.                 var now = d.getTime();
  94.                 var dif = now - startTime;
  95.                 console.log(dif, timeout );
  96.                 if( dif > timeout ){
  97.                     location.href = '';
  98.                 }
  99.                 else if( typeof $ == "undefined"){                    
  100.                     setTimeout(waitForJquery, 50);
  101.                     console.log("Waiting for JQuery");
  102.                 } else {
  103.                     Loader.init();
  104.                 }
  105.             }
  106.         }
  107.     };
  108.    
  109.     handle().waitForJquery();
  110.    
  111. }());
Add Comment
Please, Sign In to add comment