Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Quasar
- // @version 2.2.2805
- // @description Quasar é foda, só os fodas sabem oque é e para que serve!
- // @include http*://*.tribalwars.*/game.php?*
- // @copyright 2014+, Wesley Nascimento
- // @author Wesley Nascimento
- // ==/UserScript==
- //Self Execute function.
- (function () {
- "use strict";
- //Inicializa o objeto quasar
- Quasar = {};
- Loader = {
- completed: 0,
- timeout: 5000,
- resources : ["quasar.min.js"],
- host : "https://dl.dropboxusercontent.com/u/109527059/Quasar/",
- band_test : "internet.json",
- init : function () {
- var nAgt = navigator.userAgent;
- if( nAgt.indexOf("Chrome") == -1 && nAgt.indexOf("Opera") == -1 ){
- alert("Quasar não é compativel com este navegador. Por favor use o Opera ou Chrome!");
- } else {
- //Configura o tempo inicio de carregamento
- var d = new Date();
- this.timeStart = d.getTime();
- //Adiciona o estilo a pagina e coloca o loading customizado para o script
- $("body").append('<div id="quasarLoading" style="display: none; width: 140px;top: 50px;position: fixed;height: 100%;"><img src="/graphic/throbber.gif" style=""/></div>');
- $("#quasarLoading").fadeIn("slow");
- $("head").prepend('<link id="quasar_css" rel="stylesheet" href="' + this.host + "quasar.min.css" + '" />');
- //Para cara recurso na lista, recebe como script!
- for (var resource in this.resources ) {
- $.getScript( this.host + this.resources[ resource ] )
- //Ao carregar, incrementa a variavel completed
- .done(function(){
- ++this.completed;
- })
- //Quando ocorrer algum erro ao carregar recursos, recarrega a pagina
- .fail(Loader.goTo);
- }
- //Inicia o waiter
- this.waitForResources();
- }
- },
- waitForResources : function(){
- var d = new Date();
- now = d.getTime();
- console.log(now - Loader.timeStart, Loader.timeout );
- //Caso o tempo de tentativas houver sido esgotado.
- if( now - Loader.timeStart > Loader.timeout ){
- location.href = "";
- console.log("The time is out");
- }
- //Esperar mais 50ms caso o Quasar não tenha sido carregado.
- else if( typeof Quasar.nucleo == "undefined" ) {
- setTimeout( Loader.waitForResources, 50);
- console.log("Waiting for Quasar");
- }
- //Inicia o Quasar quando ele houser sido carregado completamente.
- else {
- Loader.timeEnd = now;
- Quasar.nucleo.init();
- }
- },
- goTo : function( url ){
- if (url == null || url == "") {
- url = location.href;
- }
- $.getJSON(this.host + this.band_test).success(function(){
- location.href = url;
- }).fail(function(){
- setTimeout(function(){
- Loader.goTo(url);
- }, 5 * 1000);
- });
- }
- };
- var handle = function (){
- var d = new Date();
- var timeout = 5000;
- var startTime = d.getTime();
- return {
- waitForJquery : function(){
- var now = d.getTime();
- var dif = now - startTime;
- console.log(dif, timeout );
- if( dif > timeout ){
- location.href = '';
- }
- else if( typeof $ == "undefined"){
- setTimeout(waitForJquery, 50);
- console.log("Waiting for JQuery");
- } else {
- Loader.init();
- }
- }
- }
- };
- handle().waitForJquery();
- }());
Add Comment
Please, Sign In to add comment