Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. // ==UserScript==
  2.  
  3. // @name CommandSender
  4.  
  5. // @version 0.1c
  6.  
  7. // @author Couiz
  8.  
  9. // @match *://*.plemiona.pl/*&screen=place*&try=confirm*
  10.  
  11. // @grant none
  12.  
  13. // @run-at document-start
  14.  
  15. // @updateURL https://raw.githubusercontent.com/Couiz/TribalWars/master/CommandSender/CommandSender.js
  16.  
  17. // @downloadURL https://raw.githubusercontent.com/Couiz/TribalWars/master/CommandSender/CommandSender.js
  18.  
  19. // ==/UserScript==
  20.  
  21.  
  22.  
  23. CommandSender = {
  24.  
  25. confirmButton: null,
  26.  
  27. duration: null,
  28.  
  29. dateNow: null,
  30.  
  31. offset: null,
  32.  
  33. init: function() {
  34.  
  35. $($('#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>');
  36.  
  37. this.confirmButton = $('#troop_confirm_go');
  38.  
  39. this.duration = $('#command-data-form').find('td:contains("Trwanie:")').next().text().split(':').map(Number);
  40.  
  41. this.offset = localStorage.getItem('CS.offset') || -250;
  42.  
  43. this.dateNow = this.convertToInput(new Date());
  44.  
  45. $('#CSoffset').val(this.offset);
  46.  
  47. $('#CStime').val(this.dateNow);
  48.  
  49. $('#CSbutton').click(function() {
  50.  
  51. var offset = Number($('#CSoffset').val());
  52.  
  53. var attackTime = CommandSender.getAttackTime();
  54.  
  55. localStorage.setItem('CS.offset', offset);
  56.  
  57. CommandSender.confirmButton.addClass('btn-disabled');
  58.  
  59. setTimeout(function() {
  60.  
  61. CommandSender.confirmButton.click();
  62.  
  63. },attackTime-Timing.getCurrentServerTime()+offset);
  64.  
  65. this.disabled = true;
  66.  
  67. });
  68.  
  69. },
  70.  
  71. getAttackTime: function() {
  72.  
  73. var d = new Date($('#CStime').val().replace('T',' '));
  74.  
  75. d.setHours(d.getHours()-this.duration[0]);
  76.  
  77. d.setMinutes(d.getMinutes()-this.duration[1]);
  78.  
  79. d.setSeconds(d.getSeconds()-this.duration[2]);
  80.  
  81. return d;
  82.  
  83. },
  84.  
  85. convertToInput: function(t) {
  86.  
  87. t.setHours(t.getHours()+this.duration[0]);
  88.  
  89. t.setMinutes(t.getMinutes()+this.duration[1]);
  90.  
  91. t.setSeconds(t.getSeconds()+this.duration[2]);
  92.  
  93. var a = {
  94.  
  95. y: t.getFullYear(),
  96.  
  97. m: t.getMonth() + 1,
  98.  
  99. d: t.getDate(),
  100.  
  101. time: t.toTimeString().split(' ')[0],
  102.  
  103. ms: t.getMilliseconds()
  104.  
  105. };
  106.  
  107. if (a.m < 10) {
  108.  
  109. a.m = '0' + a.m;
  110.  
  111. }
  112.  
  113. if (a.d < 10) {
  114.  
  115. a.d = '0' + a.d;
  116.  
  117. }
  118.  
  119. if (a.ms < 100) {
  120.  
  121. a.ms = '0' + a.ms;
  122.  
  123. if (a.ms < 10) {
  124.  
  125. a.ms = '0' + a.ms;
  126.  
  127. }
  128.  
  129. }
  130.  
  131. return a.y + '-' + a.m + '-' + a.d + 'T' + a.time + '.' + a.ms;
  132.  
  133. },
  134.  
  135. addGlobalStyle: function(css) {
  136.  
  137. var head, style;
  138.  
  139. head = document.getElementsByTagName('head')[0];
  140.  
  141. if (!head) { return; }
  142.  
  143. style = document.createElement('style');
  144.  
  145. style.type = 'text/css';
  146.  
  147. style.innerHTML = css;
  148.  
  149. head.appendChild(style);
  150.  
  151. }
  152.  
  153. };
  154.  
  155. CommandSender.addGlobalStyle('#CStime, #CSoffset {font-size: 9pt;font-family: Verdana,Arial;}#CSbutton {float:right;}');
  156.  
  157. var a = setInterval(function(){
  158.  
  159. if (document.getElementById('command-data-form') && jQuery) {
  160.  
  161. CommandSender.init();
  162.  
  163. clearInterval(a);
  164.  
  165. }
  166.  
  167. },1); // faster load
  168.  
  169. document.addEventListener('DOMContentLoaded', function(){
  170.  
  171. $('.server_info').prepend('<span style="float:left" >CommandSender Coded by: Couiz (xcouiz@gmail.com)</span>');
  172.  
  173. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement