Advertisement
Guest User

Untitled

a guest
Nov 10th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function () {
  2.     window.setInterval(function () {
  3.         if ($("#fleets-info-container").css('display') === 'none') return;
  4.         var current_time = Math.floor(Date.now() / 1000) - 2;
  5.         // time count
  6.         $(".fleets").each(function () {
  7.             var e = $(this).data("fleet-time") - (serverTime.getTime() - startTime) / 1000;
  8.             if (e <= 0) {
  9.                 $(this).text("-")
  10.             } else {
  11.                 $(this).text(GetRestTimeFormat(e))
  12.             }
  13.         });
  14.  
  15.         $(".fleet-time-return-remaning").each(function () {
  16.             var e = $(this).data("return-remaning") - current_time;
  17.             if (e <= 0) {
  18.                 $(this).text("-").css({'text-align': 'center'})
  19.             }
  20.             else {
  21.                 $(this).text(GetRestTimeFormat(e))
  22.             }
  23.             //change
  24.             if ($(this).text() == "-" && $(this).data("lock") == "" && getCookie("connectionError") == undefined) {
  25.                 var fleetId = String($(this).data("fleet-id"));
  26.                 //console.log('fleetCookie полет назад ='+ getCookie(fleetId));
  27.                 //var fleetId = String($(this).data("fleet-id"));
  28.                 setCookie("connectionError", 'false', 15);
  29.                 $.ajax({
  30.                     method: "POST",
  31.                     url: "game.php?page=fleetTable&mode=show",
  32.                     success: function (data) {
  33.                         var html = $(data).find("#content").children().clone()
  34.                         $("#content").empty() // clean container
  35.                         $("#content").append(html) // output new html to container
  36.                     }
  37.                 })
  38.             }
  39.         });
  40.  
  41.         $(".fleet-time-arrive-remaining").each(function ()
  42.         {
  43.             var e3 = $(this).data("arrive-remaining") - current_time;
  44.  
  45.             var e33 = $(this).data("fleet-end-stay") - current_time;
  46.             if (e3 <= 0) {
  47.                 $(this).text("").css({'text-align': 'center'});
  48.                 if (e33 > 0 || $(this).data('state') == 1 || $(this).data("lock") != "" || getCookie("connectionError") != undefined) { // trim cause return lots of spaces
  49.                 } else {
  50.                     if (!$('.fleets-info-container').is(":visible")) return
  51.                         setCookie("connectionError", 'false', 15);
  52.                         $.ajax({
  53.                             method: "POST",
  54.                             url: "game.php?page=fleetTable&mode=show",
  55.                             success: function (data) {
  56.                                 var html = $(data).find("#content").children().clone()
  57.                                 $("#content").empty() // clean container
  58.                                 $("#content").append(html) // output new html to container
  59.                             }
  60.                         })
  61.                 }
  62.             }
  63.             else {
  64.                 $(this).text(GetRestTimeFormat(e3))
  65.             }
  66.         });
  67.  
  68.         $(".fleet-stay-container").each(function () {
  69.             var e = $(this).children('.fleet-stay').data("fleet-stay") - (serverTime.getTime() - startTime) / 1000;
  70.             if (e <= 0) {
  71.                 $(this).children('.fleet-stay').text("");
  72.                 $(this).children('.fleet-stay-remaning-time-title').text("");
  73.             }
  74.             else {
  75.                 $(this).children('.fleet-stay').text(GetRestTimeFormat(e))
  76.             }
  77.         });
  78.  
  79.         $(".icon-fleet-movement").each(function () {
  80.             // var fleet_stay = $(this).data('fleet-stay') - (serverTime.getTime() - startTime) / 1000; // time left to stay; 10- server writing delay
  81.             var fleet_stay = $(this).data('fleet-end-stay') - current_time;
  82.             var flight_width = $('#fleet-movement-bg').width() - 16 - 35 - 35; // 16-ico size 35 - planetssize
  83.  
  84.             if ($(this).data('state') != 1)
  85.             {
  86.                 if (current_time > $(this).data('arrive')) {//return
  87.                     if (fleet_stay <= '0') {
  88.                         // var full_time = $(this).data('return') - $(this).data('arrive');
  89.                         //  var full_time = $(this).data('return') - $(this).data('arrive') - $(this).data('abs_stay_fleet');
  90.                         var full_time = $(this).data('return') - $(this).data('fleet-end-stay');
  91.                         var to_flew_time = $(this).data('return') - current_time;
  92.                         var to_flew_width = flight_width * to_flew_time / full_time;
  93.  
  94.                         if (to_flew_width < 0) {
  95.                             to_flew_width = 0;
  96.                         }
  97.                         $(this).css({'transform': 'rotate(180deg)'});
  98.                         $(this).css({marginLeft: to_flew_width + 'px'});
  99.                     }
  100.                     else {
  101.                         if($(this).data("fleet-owner-status") == 0) {
  102.                             $(this).css({marginLeft: flight_width + 'px'});
  103.                         } else {
  104.                             $(this).css({marginRight: flight_width + 'px'});
  105.                         }
  106.  
  107.                     }
  108.                 }
  109.                 else {
  110.                     if($(this).data("fleet-owner-status") == 0) {
  111.                         var full_time = $(this).data('arrive') - $(this).data('start-time');
  112.                         var flew_time = current_time - $(this).data('start-time');
  113.                         var flew_width = flight_width * flew_time / full_time;
  114.  
  115.                         $(this).css({marginLeft: flew_width + 'px'});
  116.                     } else {
  117.                         var full_time = $(this).data('arrive') - $(this).data('start-time');
  118.                         var flew_time = current_time - $(this).data('start-time');
  119.                         var flew_width = flight_width * flew_time / full_time;
  120.  
  121.                         $(this).css({marginRight: flew_width + 'px'});
  122.                     }
  123.                 }
  124.             }
  125.             else if ($(this).data('state') == '1')
  126.             {
  127.                 if (fleet_stay <= '0') {
  128.                     var full_time = $(this).data('return') - $(this).data('fleet-end-stay');
  129.                     var to_flew_time = $(this).data('return') - current_time;
  130.                     var to_flew_width = flight_width * to_flew_time / full_time;
  131.  
  132.                     if (to_flew_width < 0) {
  133.                         to_flew_width = 0;
  134.                     }
  135.                     $(this).css({'transform': 'rotate(180deg)'});
  136.                     $(this).css({marginLeft: to_flew_width + 'px'});
  137.  
  138.                 }
  139.                 else {
  140.                     $(this).css({marginLeft: flight_width + 'px'});
  141.                 }
  142.             }
  143.  
  144.  
  145.         });
  146.         window.setTimeout('FleetTime()', 1000);
  147.     }, 1000);
  148.  
  149.  
  150.     function fleets_info_show_hide() {
  151.         if ($("#fleets-info-container").css('display') === 'none') {
  152.             $("#fleets-info-container").show();
  153.             $("#fleets-info-show-hide-1").css({background: 'url(/styles/images/fleet_arrow_top.png) no-repeat center center'});
  154.             $("#fleets-info-show-hide-3").css({background: 'url(/styles/images/fleet_arrow_top.png) no-repeat center center'});
  155.  
  156.             $.ajax({
  157.                 method: "POST",
  158.                 url: "game.php?page=fleetTable&mode=setting",
  159.                 data: {setting: "1"}//open
  160.             });
  161.  
  162.         }
  163.         else {
  164.             $("#fleets-info-container").hide();
  165.             $("#fleets-info-show-hide-1").css({background: 'url(/styles/images/planet_selector_arrow.png) no-repeat'});
  166.             $("#fleets-info-show-hide-3").css({background: 'url(/styles/images/planet_selector_arrow.png) no-repeat'});
  167.             $.ajax({
  168.                 method: "POST",
  169.                 url: "game.php?page=fleetTable&mode=setting",
  170.                 data: {setting: "2"}//closed
  171.             });
  172.         }
  173.  
  174.     };
  175.  
  176.     $("#fleets-info-show-hide").on("click", fleets_info_show_hide);
  177.     $("#fleets-info-show-hide-3").on("click", fleets_info_show_hide);
  178.     $("#fleets-info-show-hide-1").on("click", fleets_info_show_hide);
  179.     $("#fleets-info-show-hide-2").on("click", fleets_info_show_hide);
  180.  
  181. })
  182.  
  183.  
  184.  
  185. function setCookie(name, value, lifeTime) {
  186.     var date = new Date();
  187.     date.setTime(date.getTime()+(lifeTime*1000));
  188.     var expires = "; expires="+date.toUTCString();
  189.     document.cookie = name+"="+value+expires+"; path=/";
  190. }
  191.  
  192.  
  193.  
  194. function getCookie(name) {
  195.     var matches = document.cookie.match(new RegExp(
  196.         "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  197.     ));
  198.     return matches ? decodeURIComponent(matches[1]) : undefined;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement