CowboySoberano

Enviar Comandos

Jun 12th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         CommandSender
  3. // @version      0.1c
  4. // @author       Couiz
  5. // @match        *://*.plemiona.pl/*&screen=place*&try=confirm*
  6. // @grant        none
  7. // @run-at       document-start
  8. // @updateURL    https://raw.githubusercontent.com/Couiz/TribalWars/master/CommandSender/CommandSender.js
  9. // @downloadURL  https://raw.githubusercontent.com/Couiz/TribalWars/master/CommandSender/CommandSender.js
  10. // ==/UserScript==
  11.  
  12. CommandSender = {
  13.     confirmButton: null,
  14.     duration: null,
  15.     dateNow: null,
  16.     offset: null,
  17.     init: function() {
  18.         $($('#command-data-form').find('tbody')[0]).append('<tr><td>Przybycie:</td><td> <input type="datetime-local" id="CStime" step=".001"> </td></tr><tr> <td>Offset:</td><td> <input type="number" id="CSoffset"> <button type="button" id="CSbutton" class="btn">Potwierdź</button> </td></tr>');
  19.         this.confirmButton = $('#troop_confirm_go');
  20.         this.duration = $('#command-data-form').find('td:contains("Trwanie:")').next().text().split(':').map(Number);
  21.         this.offset = localStorage.getItem('CS.offset') || -250;
  22.         this.dateNow = this.convertToInput(new Date());
  23.         $('#CSoffset').val(this.offset);
  24.         $('#CStime').val(this.dateNow);
  25.         $('#CSbutton').click(function() {
  26.             var offset = Number($('#CSoffset').val());
  27.             var attackTime = CommandSender.getAttackTime();
  28.             localStorage.setItem('CS.offset', offset);
  29.             CommandSender.confirmButton.addClass('btn-disabled');
  30.             setTimeout(function() {
  31.                 CommandSender.confirmButton.click();
  32.             },attackTime-Timing.getCurrentServerTime()+offset);
  33.             this.disabled = true;
  34.         });
  35.     },
  36.     getAttackTime: function() {
  37.         var d = new Date($('#CStime').val().replace('T',' '));
  38.         d.setHours(d.getHours()-this.duration[0]);
  39.         d.setMinutes(d.getMinutes()-this.duration[1]);
  40.         d.setSeconds(d.getSeconds()-this.duration[2]);
  41.         return d;
  42.     },
  43.     convertToInput: function(t) {
  44.         t.setHours(t.getHours()+this.duration[0]);
  45.         t.setMinutes(t.getMinutes()+this.duration[1]);
  46.         t.setSeconds(t.getSeconds()+this.duration[2]);
  47.         var a = {
  48.             y: t.getFullYear(),
  49.             m: t.getMonth() + 1,
  50.             d: t.getDate(),
  51.             time: t.toTimeString().split(' ')[0],
  52.             ms: t.getMilliseconds()
  53.         };
  54.         if (a.m < 10) {
  55.             a.m = '0' + a.m;
  56.         }
  57.         if (a.d < 10) {
  58.             a.d = '0' + a.d;
  59.         }
  60.         if (a.ms < 100) {
  61.             a.ms = '0' + a.ms;
  62.             if (a.ms < 10) {
  63.                 a.ms = '0' + a.ms;
  64.             }
  65.         }
  66.         return a.y + '-' + a.m + '-' + a.d + 'T' + a.time + '.' + a.ms;
  67.     },
  68.     addGlobalStyle: function(css) {
  69.         var head, style;
  70.         head = document.getElementsByTagName('head')[0];
  71.         if (!head) { return; }
  72.         style = document.createElement('style');
  73.         style.type = 'text/css';
  74.         style.innerHTML = css;
  75.         head.appendChild(style);
  76.     }
  77. };
  78. CommandSender.addGlobalStyle('#CStime, #CSoffset {font-size: 9pt;font-family: Verdana,Arial;}#CSbutton {float:right;}');
  79. var a = setInterval(function(){
  80.     if (document.getElementById('command-data-form') && jQuery) {
  81.         CommandSender.init();
  82.         clearInterval(a);
  83.     }
  84. },1); // faster load
  85. document.addEventListener('DOMContentLoaded', function(){
  86.     $('.server_info').prepend('<span style="float:left" >CommandSender Coded by: Couiz (xcouiz@gmail.com)</span>');
  87. });
Add Comment
Please, Sign In to add comment